Python Tkinter Basic Control Learning

Source: Internet
Author: User

#-*-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

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.