我想使用" a"来自RandNum函数的GuessNum函数 这个有可能? 说明: 1.单击新游戏按钮 2.在空文本框中输入4个数字 3.点击猜测按钮 这应该打印但我不起作用
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 :(得分:0)
而不是&#39;让它成为一个自我。&#39;在两种方法中