Advertisement
yoshi_squashy

Proof of concept - fixed number of lines input with tkinter

May 18th, 2020
1,592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. class textCollectingWindow():
  4.     def __init__(self,linesOfText,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.Text(self.root, height=linesOfText)
  13.         self.entryBox.pack()
  14.        
  15.         button = tk.Button(self.root, text = btnText,command=self.storeText)
  16.         button.pack()
  17.  
  18.         while True:
  19.             try:
  20.                 self.root.update()
  21.             except:
  22.                 break
  23.  
  24.     def storeText(self):
  25.         self.theText = self.entryBox.get("1.0", tk.END)
  26.         self.theText = self.theText[:len(self.theText)-1]
  27.         self.root.destroy()
  28.  
  29.     def getText(self):
  30.         return self.theText
  31.  
  32.  
  33. codeGetter = textCollectingWindow(2,'Enter two lines of code:','Add code')
  34.  
  35. userCode = codeGetter.getText()
  36.  
  37. with open('user\'s code.py','w') as userCodeFile:
  38.     userCodeFile.write(userCode)
  39.  
  40. print('code added.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement