我如何将wx.ScrolledWindow放入wx.SplitterWindow中?

2024-05-05 21:40:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我没想到这会这么棘手。我想得到这样的东西:

X | X

其中两个x都是滚动窗口,最终将包含大量文本,“|”是将两者分开的“拆分器”。我想要一些像大多数视觉差异给你的东西。不过,我好像没法让它发挥作用。我现在最大的问题是我违背了一些断言。当我在python中直接运行它时,它实际上绘制的是我所期望的,减去了对适当大小的一些优化,尽管存在约束冲突。不过,我的项目使用pybliographer,它在约束冲突时退出。我做错了吗?有更简单的方法吗?在

我已经包含了一个使用滚动窗口的splitterwindow示例代码的简单修改。我首先将面板放入滚动窗口中,然后使用它来设置滚动条,如wxpythonwiki中的第二个示例所示(http://wiki.wxpython.org/ScrolledWindows,抱歉,新用户无法创建两个超链接)。在

import wx

class Splitterwindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 300))
        quote = '''Whether you think that you can, or that you can't, you are usually right'''
        splitter = wx.SplitterWindow(self, -1)
        scroll1 = wx.ScrolledWindow(splitter,-1)
        panel1 = wx.Panel(scroll1, -1)
        wx.StaticText(panel1, -1, quote, (100, 100), style=wx.ALIGN_CENTRE)
        panel1.SetBackgroundColour(wx.LIGHT_GREY)
        panel1.SetAutoLayout(True)
        panel1.Layout()
        panel1.Fit()
        scroll_unit = 50
        width,height = panel1.GetSizeTuple()
        scroll1.SetScrollbars(scroll_unit,scroll_unit,width/scroll_unit,height/scroll_unit)
        scroll2 = wx.ScrolledWindow(splitter,-1)
        panel2 = wx.Panel(scroll2, -1)
        wx.StaticText(panel2, -1, quote, (100, 100), style=wx.ALIGN_CENTRE)
        panel2.SetBackgroundColour(wx.WHITE)
        panel2.SetAutoLayout(True)
        panel2.Layout()
        panel2.Fit()
        scroll_unit = 50
        width,height = panel2.GetSizeTuple()
        scroll2.SetScrollbars(scroll_unit,scroll_unit,width/scroll_unit,height/scroll_unit)
        splitter.SplitVertically(scroll1, scroll2)
        self.Centre()
        self.Show(True)

app = wx.App()
tmp = Splitterwindow(None, -1, 'splitterwindow.py')
app.MainLoop()

Tags: selfyoutrueunitwidthquotewxscroll