zoukankan      html  css  js  c++  java
  • Python的tkinter和tkinter.messagebox应用-鼠标和键盘命令绑定

    __author__ = 'Administrator'
    from tkinter import *
    import tkinter.messagebox
    
    class MainWindow:
    
        def buttonListener1(self,event):
            tkinter.messagebox.showinfo("messagebox","this is button 1 dialog")
        def buttonListener2(self,event):
            tkinter.messagebox.showinfo("messagebox","this is button 2 dialog")
        def buttonListener3(self,event):
            tkinter.messagebox.showinfo("messagebox","this is button 3 dialog")
        def buttonListener4(self,event):
            tkinter.messagebox.showinfo("messagebox","this is button 4 dialog")
    
        def __init__(self):
            self.frame = Tk()
    
            self.button1 = Button(self.frame,text = "button1",width = 10,height = 5)
            self.button2 = Button(self.frame,text = "button2",width = 10,height = 5)
            self.button3 = Button(self.frame,text = "button3",width = 10,height = 5)
            self.button4 = Button(self.frame,text = "button4",width = 10,height = 5)
    
            self.button1.grid(row = 0,column = 0,padx = 5,pady = 5)
            self.button2.grid(row = 0,column = 1,padx = 5,pady = 5)
            self.button3.grid(row = 1,column = 0,padx = 5,pady = 5)
            self.button4.grid(row = 1,column = 1,padx = 5,pady = 5)
    
            #bind代替command命令
            self.button1.bind("<Enter>",self.buttonListener1)#绑定回车
            self.button2.bind("<ButtonRelease-1>",self.buttonListener2)#绑定鼠标左键释放
            self.button3.bind("<Button-1>",self.buttonListener3)#绑定鼠标左键按下
            self.button4.bind("<ButtonRelease-1>",self.buttonListener4)
    
            self.frame.mainloop()
    
    window = MainWindow()

    程序退出命令的应用

    __author__ = 'Administrator'
    from tkinter import *
    root = Tk()
    root.title("顶层窗口")
    Button(root,text ="顶层窗口")
    Button(root,text ="禁用",state = DISABLED).pack(side = LEFT)
    Button(root,text = "确定").pack(side = LEFT)
    Button(root,text = "退出",command=root.quit).pack(side = RIGHT)
    
    root.mainloop()
  • 相关阅读:
    浅谈“踹”字典树
    2019.11.9 csp-s 考前模拟
    Luogu P1600[NOIP2016]day1 T2天天爱跑步
    Luogu P1197 [JSOI2008]星球大战
    Trie树(字典树)整理
    洛谷P3294 [SCOI2016]背单词——题解
    浅析差分及其推广(树上差分与广义差分)
    洛谷P1600 天天爱跑步——题解
    深入理解容斥原理
    花式求LCA
  • 原文地址:https://www.cnblogs.com/liguangao/p/5173685.html
Copyright © 2011-2022 走看看