Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class textCollectingWindow():
- def __init__(self,linesOfText,prompt,btnText):
- self.theText = None
- self.root = tk.Tk()
- promptElement = tk.Label(self.root, text=prompt)
- promptElement.pack()
- self.entryBox = tk.Text(self.root, height=linesOfText)
- self.entryBox.pack()
- button = tk.Button(self.root, text = btnText,command=self.storeText)
- button.pack()
- while True:
- try:
- self.root.update()
- except:
- break
- def storeText(self):
- self.theText = self.entryBox.get("1.0", tk.END)
- self.theText = self.theText[:len(self.theText)-1]
- self.root.destroy()
- def getText(self):
- return self.theText
- codeGetter = textCollectingWindow(2,'Enter two lines of code:','Add code')
- userCode = codeGetter.getText()
- with open('user\'s code.py','w') as userCodeFile:
- userCodeFile.write(userCode)
- print('code added.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement