如何使用wxpython设置相对位置?

发布于 2024-12-13 18:20:16 字数 1980 浏览 0 评论 0原文

我有一个 wxpython 列表框,其高度设置为 -1,这意味着它将自动设置为窗口的高度。有没有办法在窗口末端留下200px?

所以基本上我猜我要寻找的是(window_height - 200),留下200的空间。

-1 表示整个窗口高度。

谢谢。

编辑:我似乎无法让它与我的代码一起工作;

COLORS = ["red", "blue", "black", "yellow", "green"]
NUMBERS = ['0', '1', '2', '3', '4']
image=[];

import random
import wx
class images_tab(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        ## random test useless  t = wx.StaticText(self, -1, "This is a PageOne object", (20,20))
        self.listBox = wx.ListBox(self, size=(200, -1), choices=image, style=wx.LB_SINGLE)
#        self.button = wx.Button(self, label="Something else here? Maybe!")
        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.listBox, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
#        self.sizer.Add(self.button, proportion=1, flag=wx.ALL)

        self.SetSizer(self.sizer)



class MyNotebook(wx.Notebook):
    def __init__(self, *args, **kwargs):
        wx.Notebook.__init__(self, *args, **kwargs)

class MyPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

        self.notebook = MyNotebook(self, size=(220, -1))
        Images__tab = images_tab(self.notebook)
        # add the pages to the notebook with the label to show on the tab
        self.notebook.AddPage(Images__tab, "Click here to lookat pictures")

        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.notebook, proportion=0, flag=wx.EXPAND)
        #self.sizer.Add(self.button, proportion=0) #with button
        self.SetSizer(self.sizer)


class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.SetTitle("Python: Pictures")
        self.panel = MyPanel(self)
        app.frame = wx.Frame(parent=None, id=-1, size=(300,400))
        self.Show()


app = wx.App(False)
win = MainWindow(None, size=(600, 400))
app.MainLoop()

i have a wxpython listbox and its height set to -1, which would mean that it would automatically set to the height of the window. Is there a way to leave a 200px at the end of the window?

So basicilly i guess what i am looking for is (window_height - 200), to leave a 200 space.

-1 would go the full window height.

Thanks.

EDIT: I cant seem to get it to work with my code;

COLORS = ["red", "blue", "black", "yellow", "green"]
NUMBERS = ['0', '1', '2', '3', '4']
image=[];

import random
import wx
class images_tab(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        ## random test useless  t = wx.StaticText(self, -1, "This is a PageOne object", (20,20))
        self.listBox = wx.ListBox(self, size=(200, -1), choices=image, style=wx.LB_SINGLE)
#        self.button = wx.Button(self, label="Something else here? Maybe!")
        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.listBox, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
#        self.sizer.Add(self.button, proportion=1, flag=wx.ALL)

        self.SetSizer(self.sizer)



class MyNotebook(wx.Notebook):
    def __init__(self, *args, **kwargs):
        wx.Notebook.__init__(self, *args, **kwargs)

class MyPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

        self.notebook = MyNotebook(self, size=(220, -1))
        Images__tab = images_tab(self.notebook)
        # add the pages to the notebook with the label to show on the tab
        self.notebook.AddPage(Images__tab, "Click here to lookat pictures")

        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.notebook, proportion=0, flag=wx.EXPAND)
        #self.sizer.Add(self.button, proportion=0) #with button
        self.SetSizer(self.sizer)


class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.SetTitle("Python: Pictures")
        self.panel = MyPanel(self)
        app.frame = wx.Frame(parent=None, id=-1, size=(300,400))
        self.Show()


app = wx.App(False)
win = MainWindow(None, size=(600, 400))
app.MainLoop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗弃M 2024-12-20 18:20:16

将其放入 sizer 中: mysizer.Add(myListBox, 0, wx.BOTTOM, 200)

编辑:或者您可以使用 wx.GetDisplaySize() 获取窗口的宽度和高度,从高度中减去 200 并使用它设置列表框的大小。

Put it in a sizer: mysizer.Add(myListBox, 0, wx.BOTTOM, 200)

EDIT: Or you could use wx.GetDisplaySize() to get the width and height of the window, subtract 200 from the height and use that to set the size of the listbox.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文