- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 85字
- 2021-08-27 19:44:02
How to do it...
This program has Spinbox and Scale for selecting an integer value from 0 to 5:
import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.spinbox = tk.Spinbox(self, from_=0, to=5) self.scale = tk.Scale(self, from_=0, to=5, orient=tk.HORIZONTAL) self.btn = tk.Button(self, text="Print values", command=self.print_values) self.spinbox.pack() self.scale.pack() self.btn.pack() def print_values(self): print("Spinbox: {}".format(self.spinbox.get())) print("Scale: {}".format(self.scale.get())) if __name__ == "__main__": app = App() app.mainloop()
In the preceding code, for debugging purposes, we added a button that prints the value of each widget when you click on it:

推薦閱讀
- Oracle從入門到精通(第3版)
- Unity 2020 By Example
- Getting Started with Gulp(Second Edition)
- Visual FoxPro程序設計教程
- Learning C++ Functional Programming
- Android 7編程入門經典:使用Android Studio 2(第4版)
- Blockly創意趣味編程
- C語言程序設計學習指導與習題解答
- Windows內核編程
- Mudbox 2013 Cookbook
- C/C++代碼調試的藝術(第2版)
- Learn Linux Quickly
- Linux Networking Cookbook
- AngularJS Web Application Development Cookbook
- Web前端開發全程實戰:HTML5+CSS3+JavaScript+jQuery+Bootstrap