| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1569 人关注过本帖
标题:【萌新请教】Python GUI 无法调用方法的问题
只看楼主 加入收藏
wangzmyn1776
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-11-5
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
【萌新请教】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编辑过]

搜索更多相关主题的帖子: row END 记录 insert Text 
2019-11-05 13:01
fall_bernana
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:17
帖 子:243
专家分:2106
注 册:2019-8-16
收藏
得分:20 
回复 楼主 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()

改了一些地方.你自己对照着看吧
2019-11-05 16:44
wangzmyn1776
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-11-5
收藏
得分:0 
回复 2楼 fall_bernana
万分感谢!

我这就去学习学习,太谢谢啦
2019-11-06 09:15
快速回复:【萌新请教】Python GUI 无法调用方法的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017328 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved