Tkinter Control Learning Summary (1)

Source: Internet
Author: User

This section only covers the basic UI layout, button click callback, acquisition of user input content in the control, and acquisition of Keyboard Events and mouse events.

(1) Advantages and Disadvantages of tkinter

Tkinter is a built-in Python GUI library. One of its best advantages is that you do not need to install additional

The library can be used, and the entire library is very small and easy to get started. This is suitable for people who only want to concentrate on solving practical problems.

For some simple interfaces, tkinter is sufficient. But for me, it has a fatal drawback that it does not support the display of PNG files. In fact, the python image library can parse PNG files. However, after I take a PNG file of rgba8888 for parsing, it cannot be displayed on the tkinter control. It can only be obtained one by one pixel and drawn to the control in RGB format, this is equivalent to removing the transparency. Therefore, for me, it is no longer competent for my needs. For this reason, I don't want to spend too much time learning on tkinter. I just want to learn how to set up some simple controls. In the future, you need to learn more about it.

(2) tkinter program structure

(1) tkinter Main Loop

Each program that uses tkinter as the UI must have only one tkinter. TK () as the program

. Note: I tried to encapsulate my own controls and accidentally called tkinter twice. TK (), a strange error is reported during the second call, so remember not to call tkinter twice. TK ().

(2) create a tkinter Control

When creating each tkinter control, it must be passed in the upper-layer container attached to the control in the first parameter, for example:

Tkinter. Button (container, text = 'button copy', command = button callback)

(3) tkinter control layout

The layout placement control interface of the control in tkinter is integrated on each control. After creating a control, you can call its built-in layout function to determine how to place the control in the container. For example:

Chkbtn_var = tkinter. booleanvar () checkbox = tkinter. checkbutton (container, text = 'check box copy', variable = chkbtn_var, command = button callback) checkbox. pack (side = tkinter. top, fill = tkinter. x, padx = 10, pady = 5)



This article is from the "light" blog, please be sure to keep this source http://qq0457.blog.51cto.com/2169108/1564589

Tkinter Control Learning Summary (1)

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.