- Tkinter GUI Programming by Example
- David Love
- 165字
- 2021-08-27 18:49:09
Showing messages
Often, a GUI application will need to tell the user something. Using what we have learned at the moment, we could make several Label widgets which update depending on the results of some other functions. This would get tedious and take up a lot of space within the application's window.
A much better way to achieve this is to use a pop-up window. These can be created manually, but Tkinter also comes with a few pre-built pop-ups which are already laid out and ready to display any message the programmer passes to them.
Let's adjust our Hello World application to utilize these windows to display the chosen message to the user.
Import the messagebox module with the following statement:
import tkinter.messagebox as msgbox
Now update the non-init methods to utilize this module:
def say_hello(self):
msgbox.showinfo("Hello", "Hello World!")
def say_goodbye(self):
self.label_text.set("Window will close in 2 seconds")
msgbox.showinfo("Goodbye!", "Goodbye, it's been fun!")
self.after(2000, self.destroy)
Run this version of our application and try out both buttons.
- iOS 9 Game Development Essentials
- 新手學Visual C# 2008程序設計
- JSP開發案例教程
- iOS應用逆向工程(第2版)
- QGIS:Becoming a GIS Power User
- 精通Python自然語言處理
- Hands-On Automation Testing with Java for Beginners
- Python編程:從入門到實踐
- 低代碼平臺開發實踐:基于React
- 一塊面包板玩轉Arduino編程
- Clojure for Java Developers
- 大學計算機基礎
- Vue.js 3應用開發與核心源碼解析
- 從零開始學Android開發
- 嵌入式Linux C語言程序設計基礎教程