我用Python编写了一个模拟纸牌游戏的脚本,用户可以决定要玩多少张牌和多少堆牌。此输入由以下代码控制,其中boundary_1和boundary_2以整数间隔给出上限和下限,消息是用户输入:def input_check(boundary_1, message, boundary_2):
run = True
while run:
try:
user_input =int(input(message))
if boundary_1 <= user_input <= boundary_2:
run = False
return user_input
else:
print ("Incorrect Value, try again!")
run = True
except ValueError:
print ("Incorrect Value, try again!")
我现在想尝试使用tkinter制作一个图形用户界面,因此我想知道是否有任何方法可以将用户的输入保存到可以发送到上面的input_check()函数的变量中?我阅读了一些关于tkinter的教程,发现了以下代码:def printtext():
global e
string = e.get()
text.insert(INSERT, string)
from tkinter import *
root = Tk()
root.title('Name')
text = Text(root)
e = Entry(root)
e.pack()
e.focus_set()
b = Button(root,text='okay',command=printtext)
text.pack()
b.pack(side='bottom')
root.mainloop()
下面的代码只是在文本框中打印用户的输入,我需要的是由我的input_check()检查用户的输入,然后在文本框中打印一条错误消息,或者将输入保存到一个变量中,以便在批准后进一步使用。有什么好办法吗?
多谢提前!