2011-12-09 9 views
0

こんにちは私はこのコードを持っていないようです。私はbirthCalcメソッドがメソッド内の変数にアクセスしようとしているので、そのと思う。私の質問は、私のプログラムがそれらのGUI要素とその格納された値にアクセスできるように、これをどのように変更するべきかです。GUI内の変数へのアクセス

* birthCalcメソッドの先頭にある変数にアクセスしようとしています。

class GUI: 
    def __init__ (self): 
     self.app=Tk() 
     bottomFrame=Frame(self.app) 
     bottomFrame.pack(side="bottom",pady=10) 
     self.app.title("When will you be 1 billion seconds old? ") 
     Label(self.app,text="Please enter your birthday").pack() 
     Label(self.app, text="Month").pack(side="left",padx=2) 
     month=IntVar() 
     month.set(1) 
     months=range(1,13) 
     monthMenu=OptionMenu(self.app,month, *months) 
     monthMenu.pack(side="left") 

     Label(self.app, text="Day").pack(side="left",padx=2) 
     day=IntVar() 
     day.set(1) 
     days=range(1,32) 

     dayMenu=OptionMenu(self.app,day, *days) 
     dayMenu.pack(side="left") 

     Label(self.app, text="Year").pack(side="left",padx=2) 
     year=IntVar() 
     year.set(1901) 
     years=range(1901,2012) 
     yearMenu=OptionMenu(self.app,year, *years).pack(side="left") 

     Label(self.app, text="Hour").pack(side="left",padx=2) 
     hour=IntVar() 
     hour.set(0) 
     hours=range(0,25) 
     hourMenu=OptionMenu(self.app,hour, *hours).pack(side="left") 

     Label(self.app, text="Minute").pack(side="left",padx=2) 
     minute=IntVar() 
     minute.set(0) 
     minutes=range(00,60) 
     minuteMenu=OptionMenu(self.app,minute, *minutes).pack(side="left") 

     Label(self.app, text="Second").pack(side="left",padx=2) 
     second=IntVar() 
     second.set(0) 
     seconds=range(0,60) 
     secondMenu=OptionMenu(self.app,second, *seconds).pack(side="left") 

     Button(bottomFrame,text="Calculate", command=self.birthCalc).pack() 
     textVar=StringVar() 
     textVar.set("You will turn 1 billion seconds old on: ") 
     Label(bottomFrame,text=textVar.get()).pack(side="bottom",pady=5) 


    def birthCalc(self): 
     YEARSEC=31104000 #Values used for converting specified unit into seconds 
     MONTHSEC=2592000 #Ex. There are 60 seconds in a minute 
     DAYSEC=86400 
     HOURSEC=360 
     MINUTESEC=60 

     year=self.(yearMenu).get() #Get input 
     month=self.monthMenu.get()-1  
     day=self.dayMenu.get()-1   #Note that 1 is subtracted because months/days start at 01 (Not 00 as python assumes) 
     hour=self.hourMenu.get() 
     minute=self.minuteMenu.get() 
     second=self.secondMenu.get() 

答えて

2

__init__の機能の中に、あなたの要素をクラスとして属性として追加する必要があります。 I. monthMenu=OptionMenu(self.app,month, *months)self.monthMenu=OptionMenu(self.app,month, *months)

に変更してください
関連する問題