#-*-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 window ') Label (top, text= ' This is Window 2nd '). Pack () root = Tk () root.title (' 1th window ') # Display 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 () # Associate buttons and functions with bind mode B2 = button (root, Text = ' Clickme2 ') b2.configure (width = ten, height = 2, state = ' disabled ') b2.bind ("<Enter>", 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 you R name ') e.pack () # password Box Epwd = Entry (root, Text = ' Input your pwd ', show = ' * ') epwd.pack () # menu Def menu_click (): print ' I a M 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) # Get left mouse button click Coordinates def get_clickpoint (event): Print Event.x, event.y# framefor x in [' Red ', ' blue ', ' yellow ']: Frame (height = +, WI DTH = +, BG = x). Pack () root[' menu '] = Xmenuroot.bind (' <Button-3> ', pop) root.bind (' <Button-1> ', get_ Clickpoint) Root.mainloop ()
Python Tkinter Basic Control Learning