Python tkinter Base Control usage _python

Source: Internet
Author: User
Tags bind pack java web

This example demonstrates the use of the Python Tkinter base control and is shared for your reference. The specific method is as follows:

#-*-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 = Toplev El () Top.title (' 2nd window ') Label (top, text= ' This is Window # 2nd '). Pack () root = Tk () root.title (' 1th window ') # show built-in picture # x = Label (root, bit map= ' warning ') L = Label (root, fg= ' red ', bg= ' Blue ', text= ' Wangwei ', width=34, height=10) l.pack () # command Specifies the function B of the button call button (root, text= ' ClickMe ', Command=btn_click) b[' width ' = b[' height ' = 2 b.pack () # Use bind to associate buttons and Functions b2 = button (ro OT, Text = ' clickme2 ') b2.configure (width = ten, height = 2, state = ' disabled ') b2.bind ("<Enter>", Btn_click_bind) b 2.pack () # pop-up toplevel window B3 = Button (root, Text = ' Showtoplevel ', Command=show_toplevel) b3.pack () # input Box E = Entry (root, t ext = ' Input your name ') e.pack () # password Box Epwd = Entry (root, Text = ' Input your pwd ', show = ' * ') epwd.pack () # menu def menus _click (): print ' I amMenu ' 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 [' OK 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 (E Vent.x_root, Event.y_root) # Get the left mouse button click on the coordinates def get_clickpoint (event): Print Event.x, Event.y # Frame for x in [' Red ', ' B
Lue ', ' Yellow ']: Frame (height =, width =, bg = x). Pack () root[' menu ' = Xmenu root.bind (' <Button-3> ', pop)
 Root.bind (' <Button-1> ', Get_clickpoint) Root.mainloop ()

The effect is as shown in the following illustration:

I hope this article will help you with your Python programming.

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.