python tkinter 文本框如何储存变量_将用户输入从tkinter保存到变量并检查其内容...

我用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()检查用户的输入,然后在文本框中打印一条错误消息,或者将输入保存到一个变量中,以便在批准后进一步使用。有什么好办法吗?

多谢提前!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值