- Tkinter GUI Programming by Example
- David Love
- 90字
- 2021-08-27 18:49:08
Fixing our application
Let's get our Hello World application working as intended again using our new knowledge of Tkinter variables. After setting the title, change the label_text property as follows:
self.label_text = tk.StringVar()
self.label_text.set("Choose One")
Now, alter our other two methods like so:
def say_hello(self):
self.label_text.set("Hello World")
def say_goodbye(self):
self.label_text.set("Goodbye! \n (Closing in 2 seconds)")
self.after(2000, self.destroy)
Once again, run the application and click both buttons. Everything should now be all working as before.
Great! We now know how to take advantage of Tkinter's special variables, and it's super easy.
推薦閱讀
- Django:Web Development with Python
- 鋒利的SQL(第2版)
- 小程序開(kāi)發(fā)原理與實(shí)戰(zhàn)
- Symfony2 Essentials
- NGINX Cookbook
- Mastering Data Mining with Python:Find patterns hidden in your data
- Unity 2017 Mobile Game Development
- Java圖像處理:基于OpenCV與JVM
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)驗(yàn)指導(dǎo)
- Java程序設(shè)計(jì)教程
- Mastering ASP.NET Web API
- HTML5程序設(shè)計(jì)基礎(chǔ)教程
- 小學(xué)生C++趣味編程從入門(mén)到精通
- Raspberry Pi開(kāi)發(fā)實(shí)戰(zhàn)
- JavaWeb入門(mén)經(jīng)典