【发布时间】:2017-07-10 02:23:53
【问题描述】:
这稍微暴露了我正在构建的整个程序,但无论如何它只是前端。如果你们想自己制作应用程序,请继续。 :P
所以,正如标题所说,我正在尝试制作一个包含一个包含网格的框架的网格,并且我查看了一些类似的问题并没有完全得到答案,可能是因为我guis 和 tkinter 的新手,解决方案通常适合他们的特定程序。所以这里有一个适合我的类似问题。
我正在尝试使用如下所示的整体框架结构构建一些东西:GUI Frame structure,其中除了 ioFrame 之外的每个框架都是 2x2 网格。 ioFrame 包含两件事:输入行和输出行。简而言之,这是一个计算逻辑输入的计算器,你唯一的“数字”是真假。
这是我的自动取款机代码:
from tkinter import *;
class calculator:
#def update(self,
def __init__(self, window):
"""
Constructor method.
"""
self.toCompute = []; self.In = StringVar(); self.Out = StringVar();
# Window title
window.title("Logic Calculator");
# The set of 5 frames.
ioFrame = Frame(window, relief=GROOVE, borderwidth=3); ioFrame.grid(row=0); ioFrame.pack();
nwFrame = Frame(window); nwFrame.grid(row=1,column=0); nwFrame.pack();
neFrame = Frame(window); neFrame.grid(row=1,column=1); neFrame.pack();
swFrame = Frame(window); swFrame.grid(row=2,column=0); swFrame.pack();
seFrame = Frame(window); seFrame.grid(row=2,column=1); seFrame.pack();
# Top 2 rows: the IO portion
Label(ioFrame, textvariable=self.In, relief=SUNKEN).grid(row=0, sticky=W);
Label(ioFrame, textvariable=self.Out).grid(row=1, sticky=E);
# Top left 2x2 Frame: [ ( | ) ][ T | F ]
brlButton = Button(nwFrame, text='(', height=2, width=10).grid(row=0,column=0);
brrButton = Button(nwFrame, text=')', height=2, width=10).grid(row=0,column=1);
truButton = Button(nwFrame, text='T', height=2, width=10).grid(row=1,column=0);
falButton = Button(nwFrame, text='F', height=2, width=10).grid(row=1,column=1);
# Top right 2x2 Frame: [ AND | OOR ][ NND | NOR ]
andButton = Button(neFrame, text='and', height=2, width=10).grid(row=0,column=0);
oorButton = Button(neFrame, text='oor', height=2, width=10).grid(row=0,column=1);
nndButton = Button(neFrame, text='nnd', height=2, width=10).grid(row=1,column=0);
norButton = Button(neFrame, text='nor', height=2, width=10).grid(row=1,column=1);
# Bottom left 2x2 Frame: [ SSO | IIF ][ NSO | NIF ]
andButton = Button(swFrame, text='sso', height=2, width=10).grid(row=0,column=0);
oorButton = Button(swFrame, text='iif', height=2, width=10).grid(row=0,column=1);
nndButton = Button(swFrame, text='nso', height=2, width=10).grid(row=1,column=0);
norButton = Button(swFrame, text='nif', height=2, width=10).grid(row=1,column=1);
# Bottom right 2x2 Frame:[ EEQ | NEG ][ NEQ | === ]
eeqButton = Button(seFrame, text='eeq', height=2, width=10).grid(row=0,column=0);
negButton = Button(seFrame, text='neg', height=2, width=10).grid(row=0,column=1);
neqButton = Button(seFrame, text='neq', height=2, width=10).grid(row=1,column=0);
comButton = Button(seFrame, text='=', height=2, width=10).grid(row=1,column=1);
if __name__ == "__main__": # Only runs program if this specfic file is opened.
window = Tk(); # The window
calculator(window);
window.mainloop();
我仍然需要将命令添加到这些命令中(我已经在单独的文件中编写了这些命令),但我现在只是试图单独完成 gui。
我的问题是我的代码输出了这个结果:Current GUI。这显然与我的目标相去甚远。作为新手,我可能有一系列问题。
任何帮助将不胜感激。
【问题讨论】:
-
你用的是什么版本的python?我正在使用 python3,提供的代码甚至没有运行
-
@Nelson 你是怎么知道的?您是否知道错误是什么或在哪里?
-
@Nelson 版本 3.3.2。
-
我即将发布答案。
标签: python user-interface tkinter logic calculator