新手求助!python3.5错误ValueError: invalid literal for int() with...
发布网友
发布时间:2022-04-25 07:08
我来回答
共1个回答
热心网友
时间:2022-04-19 01:26
import random
from tkinter import *
the_number = random.randint(1, 100)
class Application(Frame):
def __init__(self,master):
super(Application,self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self): #create GUI Button
Label(self,text = "Input the number(1~100) to guess the correct number").grid(row = 0, column = 0, columnspan = 2, sticky = W)
Label(self,text = "Number: ").grid(row = 1, column = 0, sticky = W)
self.num_ent = Entry(self)
self.num_ent.grid(row = 1, column = 1, sticky = W)
self.inf_txt = Text(self, width = 75, height = 10, wrap = WORD)
self.inf_txt.grid(row = 7, column = 0, columnspan = 4)
Button(self,text = "Click to get important information",command = self.tell_inf(the_number)).grid(row = 6, column = 0, sticky = W)
def tell_inf(self,the_number):
print("\tWelcome to 'Guess My Number'!")
print("\nI'm thinking of a number between 1 and 100.")
print("Try to guess it in as few attempts as possible.\n")
print(the_number)
if self.num_ent.get() == '':
number = 0
else:
number = int(self.num_ent.get())
information = ""
if number > the_number:
information = "your number is too high, please input lower number"
elif number < the_number:
information = "your number is too low, please input higher number"
elif number == the_number:
information = "correct!"
self.inf_txt.delete(0.0, END)
self.inf_txt.insert(0.0, information)
root = Tk()
root.title("Guess Number")
app = Application(root)
root.mainloop()
追问这个虽然运行出来了,但是为什么获取不了自己输入的值啊....