2015-04-06 58 views
0

我想在使用GuessNum函数 的RandNum函数时使用“a”,这是可能的吗? 说明: 1.单击新建游戏按键 2.在空文本框中 3.click猜测按钮进入4号 4.这是应该打印,但我不工作如何在一个函数中使用另一个函数的细节?

import wx 
from wx.lib.masked import NumCtrl 
class MyFrame(wx.Frame): 
    def __init__(self,parent,id,title): 
     wx.Frame.__init__(self,parent,id,title) 
     self.panelMain = wx.Panel(self, -1) 
     panel = self.panelMain 
     #text boxes and bottons 
     self.guessTxt = wx.lib.masked.NumCtrl(self.panelMain,-1,size=(100,20),pos=(50,102)) 
     self.newGameTxt = wx.TextCtrl(self.panelMain,-1,size=(100,20),pos=(180,73)) 
     self.guessButton = wx.Button(panel,-1, "guess",pos=(180,100)) 
     self.gameButton = wx.Button(panel,-1, "start new game",pos=(50,70)) 
     #guess botton clicked 
     self.guessButton.Bind(wx.EVT_LEFT_DOWN,self.GuessNum) 
     #new game botton clicked   
     self.gameButton.Bind(wx.EVT_LEFT_DOWN,self.RandNum) 
    def RandNum(self,event): 
     import random 
     a= random.randint(1000,10000) 
     while(((a/1000 == a/100%10) or (a/1000 == a%100/10) or (a/1000==a%10)) or ((a/100%10 == a%100/10)or(a/100%10 == a%10)) or (a%100/10 == a%10)):  
      a= random.randint(1000,10000) 
     randNumber = [] 
     for i in range(4): 
      randNumber.append(0) 
     randNumber[0]=a/1000 
     randNumber[1]=a/100%10 
     randNumber[2]=a%100/10 
     randNumber[3]=a%10         
     self.newGameTxt.SetValue('****') 
     print a 
    def GuessNum(self,event): 
     print a 
     b = self.guessTxt.GetValue() 
     if((b/1000 <9) and (b/1000!=0)): 

      TheGuess =[] 
      for i in range(4): 
       TheGuess.append(0) 
      TheGuess[0]= b/1000 
      TheGuess[1]=b/100%10 
      TheGuess[2]=b%100/10 
      TheGuess[3]=b%10 

class MyGame(wx.App): 
    def OnInit(self):   
     frame = MyFrame(None, -1,"bulls and cows") 
     frame.Show(True) 
     return True 


app= MyGame() 
app.MainLoop() 
del app 

回答

0

代替“A”在两种方法中使它成为'self.a'

相关问题