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

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.

主站蜘蛛池模板: 桐乡市| 亚东县| 浏阳市| 安岳县| 宝山区| 江北区| 彰化市| 扎赉特旗| 达州市| 昌平区| 平阴县| 朝阳区| 乡城县| 望奎县| 内江市| 白朗县| 屯门区| 长岭县| 陆河县| 阜平县| 综艺| 五原县| 平邑县| 瑞金市| 茌平县| 句容市| 秦皇岛市| 新邵县| 胶州市| 抚远县| 太谷县| 延庆县| 乌什县| 汉寿县| 尚志市| 视频| 宝兴县| 合川市| 青海省| 潮安县| 安乡县|