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

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.

主站蜘蛛池模板: 东源县| 喜德县| 翁源县| 甘肃省| 宣汉县| 湖北省| 金寨县| 乐都县| 无棣县| 南平市| 息烽县| 鄂尔多斯市| 洛扎县| 上栗县| 连州市| 东乡县| 西盟| 尚志市| 双桥区| 晴隆县| 恭城| 大埔区| 桐庐县| 湘潭县| 万年县| 莱芜市| 汶上县| 鹤峰县| 泰和县| 桃源县| 宝清县| 阜阳市| 邮箱| 武强县| 昆明市| 衡阳县| 洪湖市| 宣武区| 自贡市| 松阳县| 沙雅县|