我有以下程序,用于创建非常基本的GUI:
from __future__ import with_statement
from Tkinter import *
import tkFont
import test
class main_fun():
def init_proc(self):
stLabelStatus['text']="Started executing the test...."
time.sleep(5)
def procA(self):
print "inside ProcA...."
stLabelStatus['text'] = "Running ProcA...."
time.sleep(5)
def procB(self):
print "inside ProcB...."
stLabelStatus['text'] = "Running ProcB...."
time.sleep(5)
def procC(self):
print "inside ProcC...."
stLabelStatus['text'] = "Running ProcC...."
time.sleep(5)
def procD(self):
print "inside ProcD...."
stLabelStatus['text'] = "Running ProcD...."
time.sleep(5)
def procE(self):
print "inside ProcE...."
stLabelStatus['text'] = "Running ProcE...."
time.sleep(5)
def procF(self):
print "inside ProcF...."
stLabelStatus['text'] = "Running ProcF...."
time.sleep(5)
def main_control(self):
stLabelStatus.config(text='Running Tests....')
self.init_proc()
self.procA()
self.procB()
self.procC()
self.procD()
self.procE()
self.procF()
tests=main_fun()
stGUI = Tk()
stGUI.geometry("450x300+50+50")
stGUI.resizable(0,0)
stGUI.title("Testing GUI")
arial12 = tkFont.Font(root = stGUI, family='Arial', size=12, weight='bold')
arial16 = tkFont.Font(root = stGUI, family='Arial', size=16, weight='bold')
stLabelTestNumlbl = Label(stGUI,text="Test No.")
stLabelTestNumlbl['font'] = arial12
stLabelTestNumlbl.place(x=120,y=40)
stInputTestNum = Entry(stGUI, width=6)
stInputTestNum['font'] = arial12
stInputTestNum.place(x=250,y=40)
stLabelStatuslbl = Label(stGUI,text="Status")
stLabelStatuslbl['font'] = arial12
# stLabelStatus.pack()
# stLabelStatus.grid(row=0,column=0)
stLabelStatuslbl.place(x=20,y=180)
stLabelResultlbl = Label(stGUI,text="Result")
stLabelResultlbl['font'] = arial12
stLabelResultlbl.place(x=20,y=240)
stButtonStart = Button(stGUI,text="Start", command=tests.main_control)
stButtonStart['font'] = arial16
stButtonStart.place(x=180,y=110)
stLabelStatus = Label(stGUI, text="", anchor=CENTER)
stLabelResult = Label(stGUI, text="", anchor=CENTER)
stLabelStatus.place(x=90,y=183)
stLabelResult.place(x=90,y=243)
stGUI.mainloop()
尽管GUI是创建的,但这里有几个问题:
tk
的小窗口,它与我的名为Testing GUI
的窗口一起打开(见下图)。我记得我刚开始的时候它不在那里,看起来像是我最近添加的东西创造的。我真的不明白到底是什么。我怎样才能移开那扇小小的虫子窗,或者至少把它藏起来?你知道吗stLabelStatus['text']="Running ProcA...."
和类似的语句,我也无法在运行时更新状态标签。我只能看到流中的最后一行(procF
是最后调用的函数)stLabelStatus['text']="Running ProcF...."
。你知道吗如何根据我的要求在运行时更新状态?我确信这是可能的,我犯了一些合乎逻辑的错误。你知道吗
抱歉,我错过了正确引用
tests
对象(您的自定义类)的命令。你知道吗但是这个
提供以下输出:
这说明了一个确切的问题,可能会在网络搜索结果中给出答案。你知道吗
但是通过对参数的提示,我们会注意到类定义及其唯一的方法。你会看到Python documentation or tutorial on classes并注意到你做错了:
class
没有参数,但方法必须至少有一个(self
):成功!你知道吗
使用全新的Python 2.7.13进行测试:
相关问题 更多 >
编程相关推荐