官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 平谷区| 略阳县| 桦甸市| 南汇区| 朔州市| 陈巴尔虎旗| 富顺县| 武鸣县| 南郑县| 张北县| 昌江| 司法| 呼伦贝尔市| 韶山市| 辽源市| 新晃| 宜宾市| 小金县| 平罗县| 鄂尔多斯市| 逊克县| 民和| 博兴县| 福清市| 河北区| 潜江市| 思茅市| 上饶市| 洞头县| 日照市| 揭阳市| 云梦县| 藁城市| 环江| 绥阳县| 平安县| 嘉定区| 河间市| 锡林浩特市| 巴彦淖尔市| 攀枝花市|