Advertisement
yoshi_squashy

Proof of concept - obtaining text input using tkinter

May 18th, 2020
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. class getTextWindow():
  4.     def __init__(self,prompt,btnText):
  5.         self.theText = None
  6.        
  7.         self.root = tk.Tk()
  8.        
  9.         promptElement = tk.Label(self.root, text=prompt)
  10.         promptElement.pack()
  11.        
  12.         self.entryBox = tk.Entry(self.root, width=50)
  13.         self.entryBox.pack()
  14.        
  15.         button = tk.Button(self.root, text = btnText,command=self.storeText)
  16.         button.pack()
  17.        
  18.         self.root.mainloop()
  19.  
  20.     def storeText(self):
  21.         self.theText = self.entryBox.get()
  22.         self.root.destroy()
  23.  
  24.     def getText(self):
  25.         return self.theText
  26.  
  27.  
  28. getName = getTextWindow('Enter your name:','Confirm')
  29.  
  30. playerName = getName.getText()
  31.  
  32. print(playerName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement