#-*-Coding:utf-8-*-from Tkinter import *def btn_click (): b2[' text '] = ' clicked ' Evalue = E.get () print ' btn C Lick and Entry value is%s '% Evalue def btn_click_bind (event): print ' Enter B2 ' Def show_toplevel (): top = TopLevel ( Top.title (' 2nd form ') Label (top, text= ' This is number 2nd form '). Pack () root = Tk () root.title (' 1th form ') # Show built-in picture # x = Label (Root, bitmap= ' W Arning ') L = Label (root, fg= ' red ', bg= ' Blue ', text= ' Wangwei ', width=34, height=10) l.pack () # command specifies that the button is called by the function B = button (root, text= ' ClickMe ', Command=btn_click) b[' width '] = 10b[' height '] = 2b.pack () # Bind button and Function b2 = button ( Root, Text = ' clickme2 ') b2.configure (width = ten, height = 2, state = ' disabled ') b2.bind ("<Enter>", Btn_click_bind) B2 . Pack () # popup toplevel Form 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, Comman D = menu_click) for item in [' Think in Java ', ' Java Web ', ' Android ']: submenu.add_command (label = Item, command = Me Nu_click) xmenu.add_cascade (label = ' Progame ', menu = submenu) # popup Menu def pop (event): Submenu.post (Event.x_root, Event.y_r OOT) # Get the left mouse button click on the coordinates def get_clickpoint (event): Print Event.x, event.y# framefor x in [' Red ', ' blue ', ' yellow ']: Frame (H eight =, width =, bg = x). Pack () root[' menu '] = Xmenuroot.bind (' <Button-3> ', pop) root.bind (' <Button-1> ', Get_clickpoint) Root.mainloop ()
Python Tkinter Basic Control Learning