我在从条目小部件中提取变量时遇到了问题,到目前为止,我已经完成了此操作,但我无法找到错误。我正在使用python 3。
from tkinter import *
def main():
global today,postal,user,expire,cardnum
root = Tk()
root.title("Card checker")
instruction =Label(root, text="Please enter your card details\n")
namel = Label(root, text="Name: ")
post = Label(root, text="Postal code: ")
today_date = Label(root, text="Todays date: ")
expire_date = Label(root, text="Expiry date ")
card_number = Label(root, text="Card Number: ")
date1= ()
postcode= ()
name1= ()
expire1= ()
cardno = ()
namel.grid(row=1, column =0)
post.grid(row=2, column =0)
today_date.grid(row=3, column =0)
expire_date.grid(row=4, column =0)
card_number.grid(row=5, column =0)
todaydateE= Entry(root,textvariable=date1)
postE= Entry(root,textvariable=postcode)
nameE = Entry(root,textvariable=name1)
expiredateE= Entry(root,textvariable=expire1)
cardnumberE= Entry(root,textvariable=cardno)
nameE.grid(row=1, column =1)
postE.grid(row=2, column =1)
cardnumberE.grid(row=5, column =1)
expiredateE.grid(row=4, column =1)
todaydateE.grid(row=3, column =1)
doneButton = Button(root, text= "Confirm", command=datecheck)
doneButton.grid(columnspan =2)
today= date1.get()
postal= (postcode.get())
user= name1.get()
expire= expire1.get()
cardnum = cardno.get()
def datecheck():
global today,postal,user,expire,cardnum
print(postal)
答案 0 :(得分:0)
所以你没有正确使用.get()函数。你也想制作程序,以便在事件发生后你.get()的东西,否则它将试图得到什么,因为当程序启动时,那里什么都没有。编辑了您的代码,这样如果您点击确认按钮,您将获得输入到输入框中的任何内容
sort_buffer_size
read_buffer_size
read_rnd_buffer_size
join_buffer_size