0

我一直在查看文档,但对如何使用 Tkinter 设置变量感到困惑。

我通常只是通过脚本设置变量,例如:

nb=5
path='/Users/ashleighclayton/Files
navg=24
sdthresh=25
absstepthresh=100

但是,我希望能够使用 GUI 设置这些值。目前我已经构建了这个 GUI,但我正在努力实现这个,即使它看起来很简单。(另请注意,在大多数情况下它们是整数而不是字符串)

class Application(Frame):
    def exc(self):
            execfile('currentmethod merlin.py',{'nb':nb,'path':path, 'navg':navg, 'sdthresh':sdthresh, 'absstepthresh':absstepthresh})

    def exe(self):
        execfile('new method merlin.py',{'nb':nb,'path':path, 'navg':navg, 'sdthresh':sdthresh, 'absstepthresh':absstepthresh} )    

    numblades=IntVar()


    def createWidgets(self):
        self.QUIT = Button(self)
        self.QUIT["text"] = "QUIT"
        self.QUIT["fg"]   = "red"
        self.QUIT["command"] =  self.quit

        self.QUIT.pack({"side": "left"})

        self.CRTM = Button(self)
        self.CRTM["text"] = "CRTM",
        self.CRTM["command"] = self.exc
        self.CRTM.pack({"side": "left"})

        self.ERTM = Button(self)
        self.ERTM["text"] = "ERTM",
        self.ERTM["command"] = self.exe
        self.ERTM.pack({"side": "left"})

        # this is what I attempted, but I'm unsue how to set the input as the variable. 
        self.nb = Entry(self)
        self.nb.pack(side = RIGHT)


    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()

抱歉,我是 Tkinter 的新手,因此非常感谢任何帮助,甚至只是将我指向相关文档。

4

2 回答 2

0

我通常使用 textvariable 配置选项和 Tkinter 变量,但您也可以使用 insert。http://effbot.org/tkinterbook/entry.htm

于 2013-10-08T16:24:54.510 回答
0

首先为Entry创建一个变量

self.entryVar=Tkinter.Stringvar()

然后将其与您的条目小部件链接

self.nb = Entry(self,textvariable=self.entryVar)

然后要获取 Entry 小部件的值,请使用

self.entryVar.get()
于 2013-10-09T09:43:33.570 回答