Python Tkinter basic operations and events

Source: Internet
Author: User

Basic operations

ImportTkinter as TK#introduction of TK packageWin=tk. Tk ()#Introducing Window ObjectsWin.title ("Window Title")#Window TitleWin.geometry ("200x100")#window width x HeightWin.geometry ("+500+200")#window to the top left of the screenlable=tk. Label (Win,#Parent Window Objecttext='omg! This is tk!',#the text of the labelbg='Green',#Background ColorFont= ('Arial', 12),#font and font sizeWidth=15, height=2#Label Length width    )
" "
label or other label settings style can be in string form or in array form
label[' height ']=5
label[' width ']=20
" "
#lable.pack () # Layout in the right place the pack layout is used hereLable.grid ()#layout in the right place the grid layout is used hereWin.mainloop ()#Event Loops

Action Event (command)

 #   event action   Import   Tkinter as TK  #   Click event execution function  def   P_label (): 
    global   root label  =TK. Label (Root,text= " python  "  ) label.pack () root  =TK. Tk () button  =tk. button (Root,text= "  Click button  " , Command=p_label) #   Command Click event Command  button.pack () Root.mainloop ()  

Action Event (BIND)

ImportTkinter as TKdefP_label (events):#must be followed by a parameter    GlobalRoot Label= Tk. Label (root,text='I love Python .') label.pack () root=tk. Tk () button= Tk. Button (root,text='Point Me') Button.bind ("<Button-1>", P_label)# MOUSE Click event<Button-1> indicates that the left key 2 means that the wheel 3 is the right buttonButton.pack () root.mainloop ( )

Python Tkinter basic operations and events

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.