-1
我有一段代碼,我已經返回並修復到目前爲止。 這是一個數學遊戲,產生一個問題;問這個問題;檢查它並增加評分。 我仍然是一個初學者,有一個問題,我看到很多人有問題。 雖然我仍然無法弄清楚StringVar()在tkinter入口小部件中的錯誤
我有一個進入小部件,並希望得到的信息出來,但繼續得到錯誤
可有人出了什麼問題,哪裏放V = STRINGVAR()以及爲什麼它是錯誤的(我想知道爲什麼)
這是一個WIP遊戲,所以請忽略其他錯誤。 進口的Tkinter爲TK 導入隨機爲r
score = 0
a = 0
b = 0
answer = 0
def question_gen():
global a
global b
global answer
a = r.randint(0,100)
b = r.randint(0,100)
answer = (a+b)
def question_checker():
global score
user_input = v.get
if user_input == answer:
score += 1
else:
score += 0
class Demo1:
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master).pack()
self.label = tk.Label(self.frame, text = 'Welcome To My Wonderful Math Game\n\nHow To Play\n\nWhen you pick a difficulty a new window will pop up\nYou have to answer to the question\nBefore the timer runs out\n\nGood Luck!').pack()
self.button1 = tk.Button(self.frame, text = 'Easy', width = 25, command = self.new_window).pack()
self.button2 = tk.Button(self.frame, text = 'Hard', width = 25, command = self.new_window).pack()
def new_window(self):
self.newWindow = tk.Toplevel(self.master)
self.app = Demo2(self.newWindow)
class Demo2:
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master).pack()
self.label = tk.Label(self.master, text = '{0} + {1} ='.format(a,b)).pack()
self.entry = tk.Entry(self.master, textvariable=v).pack()
self.quitButton = tk.Button(self.master, text = 'Quit', width = 25, command = self.close_windows).pack()
def close_windows(self):
self.master.destroy()
def main():
root = tk.Tk()
app = Demo1(root)
root.mainloop()
if __name__ == '__main__':
main()
你會得到什麼錯誤? –