Python Tkinter Plugin usage explained (i) (python2.7)

Source: Internet
Author: User

This article is a summary of what I learned from the Internet

I. What is Tkinter?

Tkinter is a python built-in GUI graphics library that supports multiple operating systems and is developed using TCL language;

The Python code we write will call the built-in Tkinter,tkinter to encapsulate the interface to the TK;

TK will invoke the local GUI interface provided by the operating system to complete the final GUI

Two. Use of the Tkinter module

1) from Tkinter Import * 2) Import Tkinter The use of the two is different, the problem I encountered is the following code:

<span style= "FONT-SIZE:12PX;" >   #省略部分内容   root = button (Gui,text = "error");</span>
Referenced in 2) must be referred to as below, in 1) and only as above
<span style= "FONT-SIZE:12PX;" >   root = <strong>tkinter.</strong>button (Gui,text = "error");</span>
In addition, the case of import under 3. Pyhon will also affect the compilation

Three. Tkinter Common controls

Control Describe
Label Label control; can display text and bitmaps
Button Button control; Display a button in a program ; Response message
Entry input control; for displaying a single line of text content
Checkbutton Multi-box control; for providing multiple selection boxes in a program
Listbox A list box control; a ListBox widget is used to display a list of strings to the user
Scale A range control that displays a numeric scale that is a range of numbers for the output limit
Spinbox Input controls, similar to entry, but can specify input range values
Menu Menu controls, display menu bars, drop-down menus, and pop-up menus
Message A message control that displays multiple lines of text similar to a label (but creates a new window)
Optionmenu Optional menu control; Allow the user to select a value in the menu
Radiobutton radio button control; Displays a single-selected button state
Frame A frame control that displays a rectangular area on the screen and is used as a container
TopLevel A container control that provides a separate dialog box, similar to a frame
Text Text control; for displaying multiple lines of text
Canvas A canvas control; display graphic elements such as lines or text
Event Event control;
Four. First GUI program

1.from Tkinter Import *2.root= Tk()  #初始化Tk3.label= Label(Root,text="Hello Tkinter") #创建一个label标签4.label.Pack()  #显示label标签5.root.Mainloop()  #进入消息循环

Parse each line of code

3. It can be understood that a window group (many windows) needs a family, the family name is root, so in this group each people must be in () the first to add their own family name, and then the people's own personal characteristics (name, size, etc.)

4. Can be regarded as a people for themselves in the community to declare a status (space in the window)

Five. Beautification of the first GUI program

<span style= "FONT-SIZE:12PX;" >    Import Tkinter    window=tkinter.tk ();    window["height"]=300;     window["width"]=300;    Window.title ("Im ' window"); #窗口标题    window["bg"]= ' #0099ff '; #窗口颜色, 0099FF is 16 RGB    Window.mainloop ();</span>
1.Window. resizable (False,false)
Re indicates that SIZ represents size/size able can
String up is whether the size can be reset, corresponding to the width and height of the window can be scaled. True to allow, false to not.
2.Window. MinSize (300,600)
Min indicates that the minimum size
String up is the smallest size, that is, if the above is set wide or high can be adjusted, then the width or height of the minimum can be adjusted to where? This is the setting.
Window. maxsizE (600,1200) This is the maximum width and height that can be adjusted, refer to minsize brain yourself.
3. What do we do when we want to adjust the position of the window when we start? You can use this:
Window. Geometry ("300x600+120+100")
300X600 indicates that the width and height of the window are the same as the [' width ']/[height '] property of the second section
120+100 means that in the desktop (120,100) This coordinates the window (the coordinates are the upper left corner of the window), under the Windows system we can call the corresponding API through the PYWIN32 library to get the desktop coordinate values, the window to the center of the desktop location effect.
4. If we need to set the window to "toolbar style", we can use wdindowattributes ("-toolwindow", 1), which is the Microsoft Office Quick Edit window style, Under Win8 the difference seems less obvious, xp/win7 under the obvious.

5. If we are going to write a small window to the desktop so that we can see some information in real time, we need to set the window to "sticky window", to avoid it being blocked by other windows, we need:
window.attributes ("-topmost", 1)
6. Maximized: window.state ("zoomed")
minimized: window.iconify ()
7. Everyone wants their UI to be a little bit more beautiful, let's make the window transparent now!
window.attributes ("-alpha", 0.6)
transparency from 0-1,1 is opaque, 0 is fully transparent



Python Tkinter Plugin usage explained (i) (python2.7)

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.