This example shows the usage of the Python Tkinter base control and shares it for everyone's reference. Here's how:
#-*-Coding:utf-8-*-from Tkinter import *def btn_click (): b2[' text '] = ' clicked ' Evalue = E.get () print ' BTN Click a nd Entry value is%s '% Evalue def btn_click_bind (event): print ' Enter B2 ' Def show_toplevel (): top = toplevel () top.tit Le (' 2nd window ') Label (top, text= ' This is number 2nd window '). Pack () root = Tk () root.title (' 1th window ') # Show built-in picture # x = label (root, bitmap= ' warning ') L = La Bel (Root, fg= ' red ', bg= ' Blue ', text= ' Wangwei ', width=34, height=10) l.pack () # command specifies the function called by the button B = button (root, text= ' ClickMe ', Command=btn_click) b[' width ' = 10b[' height '] = 2b.pack () # Use Bind mode to associate buttons and Functions B2 = button (root, Text = ' clickme2 ') b2 . Configure (width = ten, height = 2, state = ' disabled ') B2.bind ("
", Btn_click_bind) B2.pack () # popup toplevel Window B3 = Button (root, Text = ' Showtoplevel ', Command=show_toplevel) B3.pack () # Input Box E = Entry (root, Text = ' Input your name ') e.pack () # password Box Epwd = Entry (root, Text = ' Input your pwd ', show = ' * ') epwd.pack ( # menu Def menu_click (): print ' I am Menu ' Xmenu = menu (root) submenu = Menu (xmenu, tearoff = 0) for item in [' Java ', ' cpp ', ' C ', ' php ': xmenu.add_command (label = Item, command = Menu_click) for item in [' Think in Java ', ' Java Web ', ' Android ']: Submenu.add_command (label = Item, command = Menu_click) xmenu.add_cascade (label = ' Progame ', menu = submenu) # popup menu def pop ( Event): Submenu.post (Event.x_root, Event.y_root) # Gets the coordinates of the left mouse button click Def get_clickpoint (event): Print Event.x, event.y# Framefor x in [' Red ', ' blue ', ' yellow ']: Frame (height = +, width =, bg = x). Pack () root[' menu '] = Xmenuroot.bind ('
', pop) root.bind ("
, Get_clickpoint) root.mainloop ()
The effect is as follows:
Hopefully this article will help you with Python programming.