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

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.