wxPython移动小部件

wxPython移动小部件,python,wxpython,Python,Wxpython,我是wxPython的初学者。现在我尝试使用timer()使静态文本可移动,但问题是,当后面的文本出现时,前面的文本不会隐藏。 所以我从以下几个方面思考: (1) 这是因为我使用的是静态文本吗?当我使用其他小部件时,它可能是“可移动的”? (2) 当我一开始想用“隐藏”或“销毁”时,结果是“未定义” 任何有用的建议都会很好,下面是我的代码(python版本:2.6): 静态文本的静态部分实际上与运动无关。。。或者甚至是可变的,但从用户的角度来看,它是静态的(即他们不能改变它) 这是因为你没有改变

我是wxPython的初学者。现在我尝试使用timer()使静态文本可移动,但问题是,当后面的文本出现时,前面的文本不会隐藏。 所以我从以下几个方面思考: (1) 这是因为我使用的是静态文本吗?当我使用其他小部件时,它可能是“可移动的”? (2) 当我一开始想用“隐藏”或“销毁”时,结果是“未定义”

任何有用的建议都会很好,下面是我的代码(python版本:2.6):


静态文本的静态部分实际上与运动无关。。。或者甚至是可变的,但从用户的角度来看,它是静态的(即他们不能改变它)

这是因为你没有改变现有的文本位置,你每次都在创建一个新的文本。。。这样,您将只移动现有的一个。。。虽然你真的应该使用一个真正的计时器

def initUI(self):

    self.widgetPanel=wx.Panel(self, -1)
    self.widgetPanel.SetBackgroundColour('white')

    # Buttons for play the simulation
    playButton = wx.Button(self.widgetPanel, -1, "Play", pos=(10,10), size=(30,30))

    self.Bind(wx.EVT_BUTTON, self.play, playButton)
    playButton.SetDefault()
    self.sT = wx.StaticText(self,-1,"",size=(20,20))
    self.timer = wx.Timer()
    self.timer.Bind(wx.EVT_TIMER,self.run_st)
def play(self, event):
    self.timer.Start(1000)

def run_st(self,timerEvent):
    global i
    i = (i+1)%4
    self.sT.SetLabel("1")
    self.sT.SetPosition(pos_st[i])

非常感谢您的快速回复!现在程序显示:文件“que_simplify.py”,第32行,在播放self.timer.start()AttributeError时:“timer”对象没有属性“start”ehh try
。start
相反,我总是把它们弄混(因为python线程是
.start
)我可以问一下,如果我想要一个可移动的小部件而不是静态文本,我可以使用什么?你可以很好地移动静态文本。。。。我不知道你说的可移动是什么意思?你是说像拖放一样?由用户提供(还请注意,我忘记了计时器的速度(这是
开始的一个参数)
非常棒!现在它工作得非常完美!这就足够我心目中的“可移动”了,thx!
def run_st(self):
    global i
    i = (i+1)%4
    self.timer.Restart(1000)
    if not hasattr(self,"sT"):
        self.sT = wx.StaticText(self.widgetPanel, -1, '1', size=(20,20))
        self.sT.SetBackgroundColour('grey')
    self.sT.SetPosition(pos_st[i])
def initUI(self):

    self.widgetPanel=wx.Panel(self, -1)
    self.widgetPanel.SetBackgroundColour('white')

    # Buttons for play the simulation
    playButton = wx.Button(self.widgetPanel, -1, "Play", pos=(10,10), size=(30,30))

    self.Bind(wx.EVT_BUTTON, self.play, playButton)
    playButton.SetDefault()
    self.sT = wx.StaticText(self,-1,"",size=(20,20))
    self.timer = wx.Timer()
    self.timer.Bind(wx.EVT_TIMER,self.run_st)
def play(self, event):
    self.timer.Start(1000)

def run_st(self,timerEvent):
    global i
    i = (i+1)%4
    self.sT.SetLabel("1")
    self.sT.SetPosition(pos_st[i])