【发布时间】:2012-10-29 03:06:30
【问题描述】:
我正在为每年的温度编写一个小型 Python/Tkinter 程序。
我可以让几乎所有东西都作为文本程序运行,但我想将它实现到 GUI 中。
程序打开一个csv 文件,将其读入列表,计算出平均值以及最小和最大温度。然后,在关闭时,应用程序会将摘要保存到新的文本文件中。
我希望默认启动屏幕显示所有年份。当一个按钮被点击时,它只显示当年的数据。
这是我想要的样子:
非常简单的布局,只有 5 个按钮和每个按钮的输出。
我可以用以下方法组成顶部的按钮:
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.hi_there = Button(frame, text="All Years", command=self.All)
self.hi_there.pack(side=LEFT)
self.hi_there = Button(frame, text="2011", command=self.Y1)
self.hi_there.pack(side=LEFT)
self.hi_there = Button(frame, text="2012", command=self.Y2)
self.hi_there.pack(side=LEFT)
self.hi_there = Button(frame, text="2013", command=self.Y3)
self.hi_there.pack(side=LEFT)
self.hi_there = Button(frame, text="Save & Exit", command=self.Exit)
self.hi_there.pack(side=LEFT)
我不知道如何处理其他元素,例如标题和表格。
一旦我有了结构/框架,我想我可以填充这些字段,这样我可能会学得更好。
【问题讨论】:
-
基本上你需要制作一个
Text小部件并调用它的insert方法来添加文本字符串。我建议你找一个tkinter教程或一本关于使用它的书。为了让您开始,这里有一个 reference guide 和其他标题为 Thinking in Tkinter 的东西。 -
这是我刚刚发现的另一个好资源,名为Tkinter Wiki。
标签: python user-interface button tkinter output