Python Tkinter Basic Control Learning

Source: Internet
Author: User

Python Tkinter Basic Control Learning

#-*-Coding: UTF-8-*-from Tkinter import * def btn_click (): b2 ['text'] = 'clicked' evalue = e. get () print 'btn Click and Entry value is % s' % evalue def btn_click_bind (event): print 'enter b2' def show_toplevel (): top = Toplevel () top. title ('window 2 ') Label (top, text =' This is window 2 '). pack () root = Tk () root. title ('window 1 ') # display built-in images # x = Label (root, bitmap = 'warning') l = Label (root, fg = 'red ', bg = 'blue', text = 'hangwei', width = 34, height = 10) l. pack () # command specifies the function B = Button (root, text = 'clickme ', command = btn_click) called by the Button) B ['width'] = 10b ['height'] = 2b. pack () # bind the join Button and function b2 = Button (root, text = 'clickme2') b2.configure (width = 10, height = 2, state = 'Disabled ') b2.bind ("
 
  
", Btn_click_bind) b2.pack () # The 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) # pop-up menu def pop (event): submenu. post (event. x_root, event. y_root) # obtain the coordinate def get_clickpoint (event): print event. x, event. y # framefor x in ['red', 'blue', 'yellow']: Frame (height = 20, width = 20, bg = x ). pack () root ['menu '] = xmenuroot. bind ('
  
   
', Pop) root. bind ('
   
    
', Get_clickpoint) root. mainloop ()
   
  
 

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.