Python Tkinter Basic controls Getting Started instance

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.