【萌新请教】Python GUI 无法调用方法的问题
各位大佬好,本人是个无基础的萌新...如果有基础错误请各位不吝赐教,拜谢。需求是做一个GUI界面,展示两个label,一个text,一个entry,一个button。通过点击button获取ertry中的值并进行判断,结果输出在text中。
目前问题是,GUI的界面可以正常展示,但是执行自定义的方法时,脚本没有任何反应就结束了....附代码如下:
程序代码:
from tkinter import *
from datetime import *
root = Tk()
root.title('请假小程序')
holiday=["seek","year","others"] #定义假期类型
seek=12 #初始化假期时间
seekholiday=[]
year=15 #初始化假期时间
yearholiday=[]
othersholiday=[]
e=StringVar()
tapin = Entry(root,textvariable=e)
Texta=Text(root)
Label(root,text="命令输入框:").grid(row=0)
Label(root,text="结果显示:").grid(row=1)
tapin.grid(row=0,column=1)
Texta.grid(row=1,column=1)
Texta.insert(INSERT,('今日日期为:', '\n',date.today()))
Texta.insert(END, '\n请病假/请年假/请其他假/查看请假记录/退出?')
def getvalue():
e=tapin.get()
while e != '退出':
if e == '请病假':
seek -= 1
seekholiday.append(date.today())
Texta.insert(END, "\n当前剩余病假为:", seek)
continue
elif e == '请年假':
year -= 1
yearholiday.append(date.today())
Texta.insert(END, "\n当前剩余年假为:", year)
continue
elif e == '请其他假':
othersholiday.append(date.today())
Texta.insert(END, "\n已记录本次请假")
continue
elif e== '查看请假记录':
Texta.insert(END, "\n当前剩余病假为:", seek, '\n')
Texta.insert(END, "\n病假记录为:", seekholiday, '\n')
Texta.insert(END, "\n当前剩余年假为:", year, '\n')
Texta.insert(END, "\n年假记录为:", yearholiday, '\n')
Texta.insert("\n其他请假记录为:", othersholiday, '\n')
continue
elif e=='退出':
Texta.insert(END,"\nGoodbye")
root.mainloop()
else:
Texta.insert(END,"\n不正确的命令")
continue
button1 = Button(root, text="确认", command=getvalue())
button1.grid(row=0, column=2)[此贴子已经被作者于2019-11-5 13:03编辑过]








