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

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:

主站蜘蛛池模板: 常山县| 井研县| 和硕县| 顺昌县| 临海市| 平利县| 团风县| 永修县| 通化县| 镶黄旗| 东乌| 三穗县| 原阳县| 大连市| 罗江县| 东乡| 新津县| 乌拉特前旗| 化隆| 义乌市| 隆昌县| 达日县| 侯马市| 南京市| 潼关县| 皮山县| 奈曼旗| 湾仔区| 左云县| 巴林左旗| 扎兰屯市| 石家庄市| 普陀区| 达拉特旗| 德安县| 永康市| 西乌珠穆沁旗| 渑池县| 乐至县| 团风县| 固阳县|