tkinter杂记=>长期更新

本文介绍了使用tkinter进行GUI编程的一些实用技巧,包括3种系统信息提示方式、光标显示的修改、按钮的禁用与启用、quit与destroy的区别、按钮风格定制以及常见弹窗的实现。内容部分参考了相关论坛和博客文章。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

部分参考:

http://tieba.baidu.com/p/3082739560?pn=1

1. 3种系统信息提示方式

showinfo('greeting','Greeting') #(提示信息的标题,提示信息的内容)
showerror('Not Implemented','Not yet available')#错误提示消息
if askyesno('Verify quit','Are you sure you want to quit?'):#选择信(ask yes no=>askyesno)
    Frame(self).quit

2.改变光标显示

#Frame
toolbar=Frame(self,cursor='hand2')#cursor->光标              

3.禁用button与检测输入

#禁用buuton
self.button_ok['state']='disable'#tkinter.DISABLED

检测输入,解锁button_ok:

def active_btn(self, event=None):
    '''
    active the button_ok
    '''
    def validate():
        return self.entry_id and self.entry_passwd.get()

    if validate():
        self.button_ok['state'] = ACTIVE

##############
self.button_ok.configure(command=self.apply)

注册管理还可以参考:

http://blog.youkuaiyun.com/bnanoou/article/details/38434443

4. quit 与 destroy区别

"quit() stops the TCL interpreter. This is in most cases what you want, because your Tkinter-app will also stop. It can be a problem, if you e.g. call your app from idle. idle is itself a Tkinker-app, so if you call quit() in your app and the TCL interpreter gets terminated, idle will also terminate (or get confused ).

destroy() just terminates the mainloop and deletes all widgets. So it seems to be safer if you call your app from another Tkinter app, or if you have multiple mainloops."

taken from

http://www.daniweb.com/forums/thread66698.html

5. button 风格

tkinter.button #更多选择
tkinter.ttk.button #设置风格button.config(style='Toolbutton')
TkUtil.button()<=>tkinter.ttk.button

6.几个常见弹窗

from  tkinter.filedialog import Open,SaveAs,Directory
filename=Open(title='open').show()
filename=SaveAs().show()
filename=Directory().show()

from subprocess import call
call(filename)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值