#2
fall_bernana2019-11-05 16:44
回复 楼主 wangzmyn1776
程序代码: from tkinter import * from datetime import * import sys 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(): global root,seek,seekholiday,year,yearholiday,othersholiday e=tapin.get() if e == '请病假': print(seek) seek = seek-1 seekholiday.append(date.today().strftime('%Y-%m-%d')) Texta.insert(END, "\n当前剩余病假为:%d" % (seek)) elif e == '请年假': year -= 1 yearholiday.append(date.today().strftime('%Y-%m-%d')) Texta.insert(END, "\n当前剩余年假为:%d" % year) elif e == '请其他假': othersholiday.append(date.today().strftime('%Y-%m-%d')) Texta.insert(END, "\n已记录本次请假") elif e== '查看请假记录': Texta.insert(END, "\n当前剩余病假为:%d \n" % (seek)) Texta.insert(END, "\n病假记录为:%s \n" % (' '.join(seekholiday))) Texta.insert(END, "\n当前剩余年假为:%d \n" % (year)) Texta.insert(END, "\n年假记录为:%s\n" % (' '.join(yearholiday))) Texta.insert(END,"\n其他请假记录为:%s\n" % (' '.join(othersholiday))) elif e=='退出': Texta.insert(END,"\nGoodbye") root.destroy() else: Texta.insert(END,"\n不正确的命令") button1 = Button(root, text="确认", command=getvalue) button1.grid(row=0, column=2) root.mainloop() 改了一些地方.你自己对照着看吧 |
需求是做一个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编辑过]