2014-08-29 71 views
2

當我運行它的代碼只有一次,當我按下按鈕,但之後,當我再次按下按鈕沒有反應。拜託,我這樣的新手和我一起承擔 下面是我的代碼:該程序運行一次,當按鈕被點擊,然後什麼也沒有

from Tkinter import* 
import random 

class Love: 
    def __init__(self): 
     window = Tk() 
     window.title("Love Calculator") 
     window.geometry("300x180") 

     frame1 = Frame(window) 
     frame1.pack() 
     self.lbl = Label(frame1, fg="white", bg = "blue",   text = "Love is Pure") 
     self.lbl2= Label(frame1, fg="White", bg = "red", width="50", text = "are you meant for one another") 
     self.lbl3= Label(frame1, fg="white", bg = "green",   text = "Let FIND OUT!!") 
     self.lbl.pack() 
     self.lbl2.pack() 
     self.lbl3.pack() 

     frame2 = Frame(window) 
     frame2.pack() 
     label = Label(frame2, text = "Your Name") 
     label2 = Label(frame2, text = "Your Lovers name") 

     self.msg = StringVar() 
     entry1 = Entry(frame2, textvariable = self.msg) 

     self.out = StringVar() 
     entry2 = Entry(frame2, textvariable = self.out) 

     btCalculate=Button(frame2, command=self.processButton, text="Calculate") 
     btClear=Button( frame2, command=self.clear_textbox, text="Try Another Name") 

     label.grid(  row=1,column=1)   # .GUI-geometry 
     label2.grid(  row=2,column=1) 
     entry1.grid(  row=1,column=2) 
     entry2.grid(  row=2,column=2) 
     btCalculate.grid(row=6,column=6,sticky=E) 
     btClear.grid( row=6,column=5) 

     window.mainloop()       # .GUI-control-loop 

    def clear_textbox(self,):      # .CMD callbackHANDLER 
     entry1.delete(0, END) 
     entry2.delete(0, END) 

    def processButton(self):      # .CMD callbackHANDLER 
     example = [ 'Enter a name','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','OMG could this be love','Till death do you apart','are crazy lovers','are romantic overs','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','Eii OMG could this be love','Till death do you apart','crazy lovers','romantic lovers','O feeli wo!', 'are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','OMG, could this be love','Till death do you apart','are crazy lovers','are romantic lovers','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','OMG could this be love','Till death do you apart','are crazy lovers','are romantic lovers','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','Eii OMG could this be love','Till death do you apart','crazy lovers','romantic lovers','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','OMG, could this be love','Till death do you apart','are crazy lovers','are romantic lovers','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','OMG could this be love','Till death do you apart','are crazy lovers','are romantic lovers','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','Eii OMG could this be love','Till death do you apart','crazy lovers','romantic lovers','O feeli wo!','are friends','are lovers','are admirers','are suppose to marry','are enemies','are secrete lovers','OMG, could this be love','Till death do you apart','are crazy lovers','are romantic lovers','O feeli wo!'] 
     brief = [ 'Enter a name','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap, they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap,they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap,they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap, they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap,they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap,they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap, they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap,they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers','their friendship will thrive through the storms of life till eternity','Lovers, who will not allow anything to come between them no matter what,They will eventually get married','They might me admirers although, buh one of them is hiding some emotions, that will one day break his or her heart','Thier marriage will endure and truimph over every trouble, Always together','They are not actually enemies buh, due to one act or a reason they dont wanna be friends for now, buh i bet one day, friendship will be their portion','The Guy is afraid to make a step, the girl think i might be too cheap,they end up leaving their burning desires to the wind, buh hey one day they might make it together in marriage','It depends it might be love, it could also be illusions, so hey becareful','They are Almost at verge of marriage buh could also be very good friends till death do them apart','Crazy as it may seem, they really love each other and nothing will stop them','This guys are romantically bonded, they have sexual desires for each other, buh thats not very helthy, Because it always leads to nothing',' Just like each other and can really be fun, cause they almost like admirers'] 
                # .SET <brief> a smarter way (original post was a longest list on screen as an example "ever-seen", be a bit more polite, sir 
     self.out = str(self.out) 
     self.msg = str(self.msg) 
     Len1  = len(self.out) 
     Len2  = len(self.msg) 
     Len  = (Len2+Len1)-3 
     self.out = example[Len] 
     self.msg = brief[Len] 
     Percentage = "You're",random.randint(20,100),"% in love" 

     Percentage = str(Percentage) 
     self.lbl[ "text"]="You are",self.out 
     self.lbl2["text"]= self.msg 
     self.lbl3["text"]= Percentage 

     return; 


Love() 
+0

您應該從使用'self.msg'和'self.out'開始。這些是'StringVar's,所以你可以通過'self.msg.set('something')'來改變它們,並使用'self.msg.get()'檢索它們的信息。所以爲了清除它們,使用'self.msg.set('')'並使用它們來計算Len1使用'Len1​​ = len(self.out.get())'。 – fhdrsdg 2014-08-29 09:40:34

回答

2

它是運行多次,根據我的測試。問題似乎是,你計算Len在你第一次運行時是11,然後是每次77。這是因爲你正在從MESSAGE框中計算Len1和Len2,而不是從入口框計算出來,並且消息11(友誼力爭通過永恆風暴)恰好是再次計算時指向自身的正確字母數。

您可以通過

entry1str=self.entry1.get() 
    entry2str=self.entry2.get() 
    Len1 = len(entry1str) 
    Len2 =len(entry2str) 

而且更換

self.out=str(self.out) 
    self.msg=str(self.msg) 
    Len1 = len(self.out) 
    Len2 =len(self.msg) 

解決這個問題,當我在這裏,你需要使用self.entry1和self.entry2在大部分的地方你已經使用了entry1和entry2,否則這些框不能正確清除。

希望有幫助!

+0

感謝Phillamon,它完美的工作,因爲我想。 – 2014-08-29 12:38:30

相關問題