In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use Python's Ttk library". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Python's Ttk library".
This article explains the use of menu buttons Menubutton, progress bar Progressbar, and combo list box Combobox in the Ttk library.
The first is the menu button Menubutton. An exit menu is simply built in the code.
Menu= Menubutton (root, text= "File") menu.grid (row=0, column=0, sticky=W) file_menu = Menu (menu, tearoff=0) menu.config (menu=file_menu) file_menu.add_command (label= "Exit", command=exit)
Next is the progress bar control Progressbar.
P_value = IntVar () p_value.set (0) progress = Progressbar (root, maximum=100, variable=p_value) progress.grid (row=1, column=0, columnspan=3, sticky='ew')
Def on_timer (): if p_value.get () < progress.cget ('maximum'): p_value.set (p_value.get () + 1) else: timer.stop ()
Timer=Timer (root, 100,100, on_timer)
The maximum value of the progress bar is fixed at 100, and the value variable is specified as p_value. When the value of p_value changes, the schedule is updated, and vice versa.
The content of on_timer is to add 1 to the value of p_value each time until the maximum value of Progressbar. On_timer is called periodically by timer timer.
Next is the Combobox association code:
C_var = StringVar () c_var.set (str (timer.get_timer () def t_changed (* args): timer.set_timer (int (c_var.get () c_var.trace_variable ('wicked, t_changed)
Time_values= ['50, '100,' 200'] c_box = Combobox (root, values=time_values, textvariable=c_var, state='readonly') c_box.grid (row=2, column=0)
First construct a string variable and initialize it to the timing length of the timer. Next, set a monitoring function for this variable to modify the timing length of the timer according to the value of the variable. Finally, build a Combobox object. In this way, when the user selects a different value, the value indirectly sets the timing length of the customizer timer through the c_var variable.
The start and stop buttons are simple:
Start_btn = Button (root, text='Start', command=timer.start) start_btn.grid (row=2, column=1)
Def stop_timer (): timer.stop () p_value.set (0) stop_btn = Button (root, text='Stop', command=stop_timer) stop_btn.grid (row=2, column=2) Thank you for your reading, this is the content of "how to use Python's Ttk library". After the study of this article, I believe you have a deeper understanding of how to use Python's Ttk library, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.