在wxPython中调整面板大小时出现图形问题 [英] Graphics issue upon resizing a panel in wxPython

查看:48
本文介绍了在wxPython中调整面板大小时出现图形问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 8 OS上使用python v2.7和wxPython v3.0.(抱歉,标题令人困惑.我不知道标题应该是什么.我将尽力详细解释我的问题.)

I am working with python v2.7 and wxPython v3.0 on Windows 8 OS. (Sorry for the confusing title. I have no idea what the title should be. I shall try my best to explain my problem in detail.)

在我的应用中,我有一个带有背景图像的滚动面板.该面板在代码段中名为 mainPanel .该 mainPanel 包含其他具有透明背景的面板,分别名为 myPanelA myPanelB .这些面板 myPanelA myPanelB 包含带有一些按钮的大小调整器. PS:这只是我的真实应用程序的一个示例.在我的真实应用程序中,我有许多不同的面板和按钮.在这种情况下,补丁会变得更大且烦人.:(

In my app I have a scrolled panel with a background image. This panel is named as mainPanel in the code snippet. This mainPanelcontains other panels named as myPanelA and myPanelB that have transparent background. These panels myPanelA and myPanelB contains sizers that are containing some buttons. PS: This is just a sample of my real world app. In my real world app I have many different panels and buttons. In this case the patches are more big and annoying. :(

问题:当我水平调整窗口大小时,有时(在我的真实应用中,与该示例应用相比,它非常频繁.)我看到空白补丁在我的应用程序窗口中,如下面的示例图片所示.如何避免这种情况?如果有人可以对其进行测试并报告他们的计算机是否存在相同的问题,那将非常好(只需确保这不是Windows OS问题.我也在Windows 7上进行了测试,它也存在相同的问题.)

Problem: When I resize my windows horizontally, some times (In my real world app it is very frequent as compared to this sample app.) I see blank patches in my App windows as shown in sample images below. How can I avoid this? It would be great if some one can test this and report if they have same problem on their machine (Just to be sure this is not Windows OS issue. I tested on Windows 7 too, it has the same problem.)

更新:只需调整窗口大小并垂直滚动,您会经常看到补丁.

Update: Simply resize the window and scroll vertically, you'll see the patches quite often.

示例图像:该修补程序由箭头指向.

Sample Images: The patch is pointed by an arrow.

代码:这是我的示例代码.可以从此处下载背景图像. greensquares.jpg

Code: Here is my code sample for playing around. The background image can be downloaded from here. greensquares.jpg

import wx
import wx.lib.scrolledpanel

class gui(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, None, id, title, style=wx.DEFAULT_FRAME_STYLE)
        mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
        mainPanel.SetupScrolling()
        myImage = wx.Image('greensquares.jpg', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        myBitmap = wx.StaticBitmap(mainPanel, -1, myImage, (0, 0))
        myPanelA = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,0), size=(150,150))
        wx.StaticText(myPanelA, -1, '     MyPanelA    ')
        myButton1A = wx.Button(myPanelA, -1, size=(20,20))
        myButton2A = wx.Button(myPanelA, -1, size=(20,20))
        mySizerA = wx.BoxSizer(wx.HORIZONTAL)
        mySizerA.Add(myButton1A, 0, wx.ALL, 20)
        mySizerA.Add(myButton2A, 0, wx.ALL, 20)
        myPanelA.SetSizer(mySizerA)
        myPanelA.Layout()

        myPanelB = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,130), size=(250,200))
        wx.StaticText(myPanelB, -1, '      MyPanelB    ')
        myButton1B = wx.Button(myPanelB, -1, size=(20,20))
        myButton2B = wx.Button(myPanelB, -1, size=(20,20))
        myButton3B = wx.Button(myPanelB, -1, size=(20,20))
        myButton4B = wx.Button(myPanelB, -1, size=(20,20))
        mySizerB1 = wx.BoxSizer(wx.HORIZONTAL)
        mySizerB1.Add(myButton1B, 0, wx.ALL, 20)
        mySizerB1.Add(myButton2B, 0, wx.ALL, 20)
        mySizerB1.Add(myButton3B, 0, wx.ALL, 20)
        mySizerB1.Add(myButton4B, 0, wx.ALL, 20)
        myButton5B = wx.Button(myPanelB, -1, size=(20,20))
        myButton6B = wx.Button(myPanelB, -1, size=(20,20))
        myButton7B = wx.Button(myPanelB, -1, size=(20,20))
        myButton8B = wx.Button(myPanelB, -1, size=(20,20))
        mySizerB2 = wx.BoxSizer(wx.HORIZONTAL)
        mySizerB2.Add(myButton5B, 0, wx.ALL, 20)
        mySizerB2.Add(myButton6B, 0, wx.ALL, 20)
        mySizerB2.Add(myButton7B, 0, wx.ALL, 20)
        mySizerB2.Add(myButton8B, 0, wx.ALL, 20)
        mySizerC = wx.BoxSizer(wx.VERTICAL)
        mySizerC.Add(mySizerB1)
        mySizerC.Add(mySizerB2)
        myPanelB.SetSizer(mySizerC)
        myPanelB.Layout()

if __name__ == '__main__':
    app = wx.App()
    frame = gui(parent=None, id=-1, title="My-App")
    frame.Show()
    app.MainLoop()

谢谢您的时间.

推荐答案

我终于找到了解决方案.除了 multiphrenic 所建议的内容外,我还将滚动事件绑定到了 OnResize().因此,任何滚动事件 EVT_SCROLL 都会出现在面板上也会被更新.在Windows7,带有python v2.7和wxPython v3.0的8 OS上运行良好.

I finally found the solution. In addition to what multiphrenic has suggested I have also binded the scroll event to a the OnResize(). So, that when ever any scroll event EVT_SCROLL occurs the panels will be updated too. It is working fine on Windows7, 8 OS with python v2.7 and wxPython v3.0.

工作代码:

import wx
import wx.lib.scrolledpanel

class gui(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, None, id, title, style=wx.DEFAULT_FRAME_STYLE)
        mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
        mainPanel.SetupScrolling()
        myImage = wx.Image('greensquares.jpg', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        myBitmap = wx.StaticBitmap(mainPanel, -1, myImage, (0, 0))
        self.myPanelA = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,0), size=(150,150))
        wx.StaticText(self.myPanelA, -1, 'self.myPanelA')
        myButton1A = wx.Button(self.myPanelA, -1, size=(20,20))
        myButton2A = wx.Button(self.myPanelA, -1, size=(20,20))
        mySizerA = wx.BoxSizer(wx.HORIZONTAL)
        mySizerA.Add(myButton1A, 0, wx.ALL, 20)
        mySizerA.Add(myButton2A, 0, wx.ALL, 20)
        self.myPanelA.SetSizer(mySizerA)
        self.myPanelA.Layout()

        self.myPanelB = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,130), size=(250,200))
        wx.StaticText(self.myPanelB, -1, 'self.myPanelB')
        myButton1B = wx.Button(self.myPanelB, -1, size=(20,20))
        myButton2B = wx.Button(self.myPanelB, -1, size=(20,20))
        myButton3B = wx.Button(self.myPanelB, -1, size=(20,20))
        myButton4B = wx.Button(self.myPanelB, -1, size=(20,20))
        mySizerB1 = wx.BoxSizer(wx.HORIZONTAL)
        mySizerB1.Add(myButton1B, 0, wx.ALL, 20)
        mySizerB1.Add(myButton2B, 0, wx.ALL, 20)
        mySizerB1.Add(myButton3B, 0, wx.ALL, 20)
        mySizerB1.Add(myButton4B, 0, wx.ALL, 20)
        myButton5B = wx.Button(self.myPanelB, -1, size=(20,20))
        myButton6B = wx.Button(self.myPanelB, -1, size=(20,20))
        myButton7B = wx.Button(self.myPanelB, -1, size=(20,20))
        myButton8B = wx.Button(self.myPanelB, -1, size=(20,20))
        mySizerB2 = wx.BoxSizer(wx.HORIZONTAL)
        mySizerB2.Add(myButton5B, 0, wx.ALL, 20)
        mySizerB2.Add(myButton6B, 0, wx.ALL, 20)
        mySizerB2.Add(myButton7B, 0, wx.ALL, 20)
        mySizerB2.Add(myButton8B, 0, wx.ALL, 20)
        mySizerC = wx.BoxSizer(wx.VERTICAL)
        mySizerC.Add(mySizerB1)
        mySizerC.Add(mySizerB2)
        self.myPanelB.SetSizer(mySizerC)
        self.myPanelB.Layout()

        self.Bind(wx.EVT_SIZE, self.OnResize)
        self.Bind(wx.EVT_SCROLL, self.OnResize)

    def OnResize(self, e):
        self.myPanelA.Update()
        self.myPanelB.Update()
        e.Skip()

if __name__ == '__main__':
    app = wx.App()
    frame = gui(parent=None, id=-1, title="My-App")
    frame.Show()
    app.MainLoop()

这篇关于在wxPython中调整面板大小时出现图形问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆