2013-10-08 38 views
0

我一直在查看文档,但很困惑如何使用Tkinter设置变量。使用GUI设置值

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

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,因此任何帮助将是非常赞赏,甚至只是指着我的有关文件。

回答

0

首先为输入变量

self.entryVar=Tkinter.Stringvar() 

然后你进入小窗口链接它

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

然后让文本输入构件的值,可以使用

self.entryVar.get() 
+0

当我想用nb,我怎么实际访问它?所以nb在'exe'方法中指定,但是如何从GUI中检索它?抱歉! .p ..感谢您的帮助:) –

+0

如果您想将GUI中的值设置为脚本,您可以随时使用Dictionary获取和设置这些值 – Gogo