【发布时间】:2015-06-06 04:48:27
【问题描述】:
我似乎在 Tkinter 的网格问题上苦苦挣扎,我是新手,已经浏览了这个论坛和网络,但没有找到答案。
我希望两个按钮和标签填充固定大小为 320 x 240 的网格。我最初遇到了粘性问题,并且阅读了网络以 3 种不同的方式编写它,但没有一个会抛出错误,但它们都不起作用。
这是我的代码:
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
self.setLounge = 21.0
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.lou_dec = tk.Button(self)
self.lou_dec["text"] = "<"
self.lou_dec["command"] = self.louDec
self.lou_dec.grid(row=1, column=1, sticky=("N", "S", "E", "W"))
self.lblLouTemp = tk.Label(self)
self.lblLouTemp["text"] = self.setLounge
self.lblLouTemp.grid(row=1, column=2, sticky=(tk.N + tk.S + tk.E + tk.W))
self.lou_inc = tk.Button(self)
self.lou_inc["text"] = ">"
self.lou_inc["command"] = self.louInc
self.lou_inc.grid(row=1, column=3, sticky=(tk.N, tk.S, tk.E, tk.W))
def louDec(self):
self.setLounge -= 0.5
print ("%s" % self.setLounge)
fo = open("/home/tony/Code/tempreg.txt", "w")
fo.write("%s" % self.setLounge)
fo.close()
def louInc(self):
self.setLounge += 0.5
print ("%s" % self.setLounge)
fo = open("/home/tony/Code/tempreg.txt", "w")
fo.write("%s" % self.setLounge)
fo.close()
root = tk.Tk()
root.title("Heating Controller")
root.geometry("320x240")
app = Application(master=root)
app.mainloop()`
非常感谢
【问题讨论】: