Python Tkinter Base Control usage

Source: Internet
Author: User
This example shows the usage of the Python Tkinter base control and shares it for everyone's reference. Here's how:

#-*-Coding:utf-8-*-from Tkinter import *def btn_click (): b2[' text '] = ' clicked ' Evalue = E.get () print ' BTN Click a nd Entry value is%s '% Evalue def btn_click_bind (event): print ' Enter B2 ' Def show_toplevel (): top = toplevel () top.tit Le (' 2nd window ') Label (top, text= ' This is number 2nd window '). Pack () root = Tk () root.title (' 1th window ') # Show built-in picture # x = label (root, bitmap= ' warning ') L = La Bel (Root, fg= ' red ', bg= ' Blue ', text= ' Wangwei ', width=34, height=10) l.pack () # command specifies the function called by the button B = button (root, text= ' ClickMe ', Command=btn_click) b[' width ' = 10b[' height '] = 2b.pack () # Use Bind mode to associate buttons and Functions B2 = button (root, Text = ' clickme2 ') b2 . Configure (width = ten, height = 2, state = ' disabled ') B2.bind ("
 
  
   ", 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 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, 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) # Gets the coordinates of the left mouse button click Def get_clickpoint (event): Print Event.x, event.y# Framefor x in [' Red ', ' blue ', ' yellow ']: Frame (height = +, width =, bg = x). Pack () root[' menu '] = Xmenuroot.bind (' 
   
     ', pop) root.bind (" 
    
     , Get_clickpoint) root.mainloop ()
      

   
  
 

The effect is as follows:

Hopefully this article will help you with Python programming.

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