0
我的朋友和我在一個猜數遊戲爲學校項目的工作,但我們似乎無論什麼時候,無法找到與我們的Tkinter程序中的問題。主要目標是讓計算機生成一個1-100的數字,用戶必須猜出數字。我們幾乎完成了大部分工作,但是每當我們猜出數字時,即使我們猜測的數字低於程序生成的數字,程序總是返回「更高」。請幫忙!!Tkinter的猜數字遊戲不工作
我已經找到了工作程序,做我們想要的,但我真的想了解什麼地方出了問題我們的節目
我已經插入下面我們的節目:
from Tkinter import *
import random
frame = Tk()
frame.geometry("500x500")
frame.title("guess the number")
global ability
ability = random.randint(1,100)
print ability
def retrieve_input():
input = t1.get("1.0",'end-1c')
return input
def startFunction():
global t2
frame.destroy()
frame2 = Tk()
frame2.geometry("500x247")
frame2.title("guess the number")
l1 = Label(text="The Number Guessing Game", font=("Helvetica", 27))
l1.place(x=10, y=10)
l2 = Label(text="Guess your number here (0-100)")
l2.place(x=10, y=100)
t1 = Text(width= 5, height= 1)
t1.place(x= 10, y= 124)
l3 = Label(text="Higher or Lower?")
l3.place(x=10, y=190)
t2 = Text(width= 15, height= 1)
t2.place(x= 10, y= 214)
b1 = Button(text="Enter", width= 5, height= 1, command= numberFunction)
b1.place(x= 10, y= 150)
def numberFunction():
global ability,t2
if input() == ability:
t2.insert(END,"correct")
if input() > ability:
t2.insert(END,"lower")
if input() < ability:
t2.insert(END,"higher")
b1 = Button(text="START", width=12, height=2, command=startFunction)
b1.place(x=210, y=210)
frame.mainloop()
當我嘗試運行代碼我得到:'的EOFError:EOF當在線閱讀一行'if input()== ability:'。您無法在Tkinter應用程序中使用這種輸入方式。對於你在做什麼,你將需要創建和使用'Entry'小部件。 – martineau