Share an introductory example of Python Tkinter base control usage, including window display, display of built-in images, popup windows, menus, and more.
Example, Python tkinter the use of the underlying control
#-*-coding:utf-8-*- fromTkinterImport*defBtn_click (): b2['text'] ='clicked'Evalue=E.get ()Print 'btn Click and Entry value is%s'%EvaluedefBtn_click_bind (event):Print 'Enter B2'defShow_toplevel (): Top=toplevel () top.title ('window No. 2nd') Label (top, text='This is window number 2nd .'). Pack () root=Tk () root.title ('Window No. 1th')#Show built-in pictures#x = Label (root, bitmap= ' warning ')L = Label (root, fg='Red', bg='Blue', text='Wangwei', Width=34, height=10) L.pack ()#command specifies the function called by the buttonb = Button (Root, text='ClickMe', command=Btn_click) b['width'] = 10b['Height'] = 2B.pack ()#associating buttons and functions with Bind modeB2 = Button (root, Text ='clickme2') b2.configure (width= Ten, height = 2, state ='Disabled') B2.bind ("<Enter>", Btn_click_bind) b2.pack ()#pop-up toplevel windowB3 = Button (root, Text ='Showtoplevel', command=show_toplevel) b3.pack ()#Input BoxE = Entry (root, Text ='Input your name') E.pack ()#Password BoxEpwd = Entry (root, Text ='Input your pwd', show ='*') Epwd.pack ()#MenudefMenu_click ():Print 'I am Menu'Xmenu=Menu (Root) submenu= Menu (Xmenu, Tearoff =0) forIteminch['Java','CPP','C','PHP']:xmenu.add_command (Label= Item, Command =Menu_click) forIteminch['Think in Java','Java Web','Android']:submenu.add_command (Label= Item, Command =Menu_click) xmenu.add_cascade (label='Progame', menu =submenu)#pop-up menudefPop (event): Submenu.post (Event.x_root, Event.y_root)#www.jbxue.com#get the coordinates of the left mouse button clickdefGet_clickpoint (event):PrintEvent.x, Event.y#Frame forXinch['Red','Blue','Yellow']:frame (Height= A, width =, BG =x). Pack () root['Menu'] =Xmenuroot.bind ('<Button-3>', Pop) root.bind ('<Button-1>', Get_clickpoint) root.mainloop ()
:
Python Tkinter Basic controls Getting Started instance