Python tkinter and tkinter. messagebox apps-bind the mouse to the keyboard command, tkintermessagebox

Source: Internet
Author: User

Python tkinter and tkinter. messagebox apps-bind the mouse to the keyboard command, tkintermessagebox

 

_ Author _ = 'admin' from tkinter import * import tkinter. messageboxclass 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 instead of command self. button1.bind ("<Enter>", self. buttonListener1) # bind the carriage return self. button2.bind ("<ButtonRelease-1>", self. buttonListener2) # bind the left mouse button to release self. button3.bind ("<Button-1>", self. buttonListener3) # bind the left mouse button and press self. button4.bind ("<ButtonRelease-1>", self. buttonListener4) self. frame. mainloop () window = MainWindow ()

 

 

Application of program exit command

 

_ Author _ = 'admin' from tkinter import * root = Tk () root. title ("top-level window") Button (root, text = "top-level window") Button (root, text = "DISABLED", state = DISABLED ). pack (side = LEFT) Button (root, text = "OK "). pack (side = LEFT) Button (root, text = "quit", command = root. quit ). pack (side = RIGHT) root. mainloop ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.