This example demonstrates the use of the Python Tkinter base control and is shared for your reference. The specific method is as follows:
#-*-Coding:utf-8-*-from tkinter import * def btn_click (): b2[' text '] = ' clicked ' Evalue = E.get () print ' btn Click and Entry value is%s '% Evalue def btn_click_bind (event): print ' Enter B2 ' Def show_toplevel (): top = Toplev El () Top.title (' 2nd window ') Label (top, text= ' This is Window # 2nd '). Pack () root = Tk () root.title (' 1th window ') # show built-in picture # x = Label (root, bit map= ' warning ') L = Label (root, fg= ' red ', bg= ' Blue ', text= ' Wangwei ', width=34, height=10) l.pack () # command Specifies the function B of the button call button (root, text= ' ClickMe ', Command=btn_click) b[' width ' = b[' height ' = 2 b.pack () # Use bind to associate buttons and Functions b2 = button (ro OT, Text = ' clickme2 ') b2.configure (width = ten, height = 2, state = ' disabled ') b2.bind ("<Enter>", Btn_click_bind) b 2.pack () # pop-up toplevel window B3 = Button (root, Text = ' Showtoplevel ', Command=show_toplevel) b3.pack () # input Box E = Entry (root, t ext = ' Input your name ') e.pack () # password Box Epwd = Entry (root, Text = ' Input your pwd ', show = ' * ') epwd.pack () # menu def menus _click (): print ' I amMenu ' 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 [' OK in Java ', ' Java Web ', ' Android ']: submenu.add_command (label = Item, command = Menu_click) xmenu.add_cascade (label = ' Progame ', menu = submenu) # pop-up menu def pop (event): Submenu.post (E Vent.x_root, Event.y_root) # Get the left mouse button click on the coordinates def get_clickpoint (event): Print Event.x, Event.y # Frame for x in [' Red ', ' B
Lue ', ' Yellow ']: Frame (height =, width =, bg = x). Pack () root[' menu ' = Xmenu root.bind (' <Button-3> ', pop)
Root.bind (' <Button-1> ', Get_clickpoint) Root.mainloop ()
The effect is as shown in the following illustration:
I hope this article will help you with your Python programming.