In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Python's Tkinter library". In daily operation, I believe many people have doubts about how to use Python's Tkinter library. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to use Python's Tkinter library". Next, please follow the editor to study!
Using the Tkinter library, you can define the style of each control, but the other side of doing so is that the style of the software is independent of the operating system, which is somewhat different.
To solve this problem, Tkinter has provided another set of ttk controls after version 8. 5. These controls adjust the usage of the control on the basis of inheriting the usage of the tkinter control, and can automatically use the style of the operating system while using it more consistently.
The only difference from the previous control is that it is more like a normal Windows program. The next step is to introduce the code, starting with importing the ttk library.
From tkinter import * from tkinter.ttk import *
Building the main window has not changed:
# create the main windowroot = Tk ()
Build the top standard button:
S_frame = LabelFrame (root, text='Standard Button') s_frame.grid (row=0, column=0) s_button = Button (s_frame, text='Button', width=12) s_button.grid (row=0, column=0)
It is important to note that because of the way the ttk library is imported, the controls in the ttk library are used here. Next, build the CheckButton example:
C_frame = LabelFrame (root, text='CheckButton') c_frame.grid (row=1, column=0)
Def d_changed (* args): c_text.set ('Value= {}' .format (d3.get (), d2.get (), d1.get (), d0.get ()
C_text = StringVar () c_text.set ('Value=0000') c_label = Label (c_frame, textvariable=c_text, width=10) c_label.grid (row=0, column=0) d3 = IntVar () d3.trace_variable (' c_frame, d_changed) c_button = Checkbutton (c_frame, text='D3', variable=d3) c_button.grid (row=0, column=1) D2 = IntVar () d2.trace_variable ('walled, d_changed) c_button = Checkbutton (c_frame, text='D2' Variable=d2) c_button.grid (row=0, column=2) D1 = IntVar () d1.trace_variable ('walled, d_changed) c_button = Checkbutton (c_frame, text='D1',variable=d1) c_button.grid (row=0, column=3) d0 = IntVar () d0.trace_variable (' wicked, d_changed) c_button = Checkbutton (c_frame, text='D0', variable=d0) c_button.grid (row=0, column=4) d3.set (0) d2.set (0) d1.set (0) d0.set (0)
Build the Radiobutton:
R_frame = LabelFrame (root, text='RadioButton') r_frame.grid (row=2, column=0)
R_label = Label (r_frame, text='Value=0', width=10) r_label.grid (row=0, column=0) def r_changed (* arg): r_label.configure (text='Value='+str (r_value.get ()) r_value = IntVar () r_value.trace_variable ('wow, r_changed) r_value.set (0) r_button = Radiobutton (r_frame, text='0', variable=r_value, value=0) r_button.grid (row=0, column=1) r_button = Radiobutton (r_frame Text='1', variable=r_value, value=1) r_button.grid (row=0, column=2) r_button = Radiobutton (r_frame, text='2', variable=r_value, value=2) r_button.grid (row=0, column=3) r_button = Radiobutton (r_frame, text='3', variable=r_value, value=3) r_button.grid (row=0, column=4)
Finally, start the main loop:
Root.mainloop ()
If we don't implement the instructions, the reader will probably not notice that we are using controls in the ttk library.
This is a great thing.
At this point, the study on "how to use Python's Tkinter library" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.