如何在wxpython中重新定位打开的窗口

如何在wxpython中重新定位打开的窗口,wxpython,Wxpython,当我在程序中初始化主窗口时,我可以使用以下方法设置窗口位置: self.MoveXY(G_hpos,G_vpos) 或 self.Move(wx.Point(G_hpos,G_vpos)) 或 self.SetPosition(wx.Point(G_hpos,G_vpos)) 它们都工作得同样好,但是,如果以后我想使用相同的代码更改初始位置,但在同一类中的另一个函数中,什么都不会发生。 我错过了一些非常简单的事情,或者我只是有一天头发不好。 注意:这是在使用Linux这真是糟糕的一天

当我在程序中初始化主窗口时,我可以使用以下方法设置窗口位置:

self.MoveXY(G_hpos,G_vpos)    

self.Move(wx.Point(G_hpos,G_vpos))


self.SetPosition(wx.Point(G_hpos,G_vpos))

它们都工作得同样好,但是,如果以后我想使用相同的代码更改初始位置,但在同一类中的另一个函数中,什么都不会发生。
我错过了一些非常简单的事情,或者我只是有一天头发不好。
注意:这是在使用Linux

这真是糟糕的一天
在另一个窗口实际更改之前,我试图根据输入更改位置,因此本质上我是在将位置更改为当前位置。
对于任何对该问题感兴趣的人,以下是一个演示:

# -*- coding: utf-8 -*-
import wx
import time
class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
#        kwds["pos"] = (10,10)
        self.frame = wx.Frame.__init__(self, *args, **kwds)
        self.SetTitle("Move around the screen")
        self.InitUI()

    def InitUI(self):
        self.location1 = wx.Point(10,10)
        self.location2 = wx.Point(500,500)
        self.panel1 = wx.Panel(self)
        self.button1 = wx.Button(self.panel1, -1, label="Move", size=(80,25), pos=(10,10))
        self.button1.Bind(wx.EVT_BUTTON, self.OnItem1Selected)
        self.Show()
        self.Move(self.location1)

    def OnItem1Selected(self, event):
        self.MoveAround()

    def MoveAround(self):
        #Judder effect by moving the window
        for i in range(30):
            curr_location = self.GetPosition() #or self.GetPositionTuple()
            if curr_location == self.location1:
                print ("moving to ", self.location2)
                self.Move(self.location2) #Any of these 3 commands will work
    #            self.MoveXY(500,500)
    #            self.SetPosition(wx.Point(500,500), wx.SIZE_USE_EXISTING)
            else:
                print ("moving to ", self.location1)
                self.Move(self.location1) #Any of these 3 commands will work
    #            self.MoveXY(10,10)
    #            self.SetPosition(wx.Point(10,10), wx.SIZE_USE_EXISTING)
            self.Update()
            time.sleep(0.1)

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame(None)
    app.MainLoop()
注意:在您的代码返回到主循环之前,移动本身似乎不会发生,因此,例如,如果您试图通过在同一函数内多次更改位置几秒钟来创建抖动效果,您将只看到它移动到其最终位置,而没有抖动


缺少的元素实际上是对
self.Update()
的调用

发布一个简短完整的示例将是一个良好的开端:或者