wxpython:如何设置wxnotebook的宽度和高度?
我遇到了麻烦,我相信是尺寸确定者。我无法按照我想要的方式设置笔记本的大小。现在我放了一个按钮,按钮的位置决定了笔记本的大小(它将拉伸它),但是我希望它能够在不使用按钮的情况下执行此操作。我已经尝试过它,但是我无法让它自行改变。
如果您不明白我的意思,请运行以下代码。
import random
import wx
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1LISTBOX1,
] = [wx.NewId() for _init_ctrls in range(4)]
########################################################################
class TabPanel(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent):
""""""
wx.Panel.__init__(self, parent=parent)
colors = ["red", "blue", "gray", "yellow", "green"]
self.SetBackgroundColour(random.choice(colors))
sampleList = ['0', '1', '2', '3', '4']
listBox = wx.ListBox(self, -1, (20, 20), (80, 120), sampleList, wx.LB_SINGLE)
listBox.SetSelection(3)
#This is the button!!!!
btn = wx.Button(self, label="Create new")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(btn,300,400, wx.ALL, 10)
self.SetSizer(sizer)
########################################################################
class DemoFrame(wx.Frame):
"""
Frame that holds all other widgets
"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY,
"Notebook Tutorial",
size=(600,400)
)
panel = wx.Panel(self)
notebook = wx.Notebook(panel)
tabOne = TabPanel(notebook)
notebook.AddPage(tabOne, "things")
tabTwo = TabPanel(notebook)
notebook.AddPage(tabTwo, "other things")
sizer = wx.BoxSizer(400)
sizer.Add(notebook)
panel.SetSizer(sizer)
#menu bar
status=self.CreateStatusBar()
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
first.Append(wx.NewId(),"New","Creates A new file")
first.Append(wx.NewId(),"ADID","Yo")
menubar.Append(first,"File")
menubar.Append(second,"Edit")
self.SetMenuBar(menubar)
self.Layout()
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = DemoFrame()
app.MainLoop()
非常感谢您的浏览。
i am having troubles, with I believe is the sizers. I cannot set the size of the notebook the way i want it to be. Right now I put a button and the position of the button determines the size of the notebook (it will stretch it) however i want it to just be able to do this without using the button. I have played around with it however i cannot get it to change by itself.
Please run the following code if you do not understand what I mean.
import random
import wx
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1LISTBOX1,
] = [wx.NewId() for _init_ctrls in range(4)]
########################################################################
class TabPanel(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent):
""""""
wx.Panel.__init__(self, parent=parent)
colors = ["red", "blue", "gray", "yellow", "green"]
self.SetBackgroundColour(random.choice(colors))
sampleList = ['0', '1', '2', '3', '4']
listBox = wx.ListBox(self, -1, (20, 20), (80, 120), sampleList, wx.LB_SINGLE)
listBox.SetSelection(3)
#This is the button!!!!
btn = wx.Button(self, label="Create new")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(btn,300,400, wx.ALL, 10)
self.SetSizer(sizer)
########################################################################
class DemoFrame(wx.Frame):
"""
Frame that holds all other widgets
"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY,
"Notebook Tutorial",
size=(600,400)
)
panel = wx.Panel(self)
notebook = wx.Notebook(panel)
tabOne = TabPanel(notebook)
notebook.AddPage(tabOne, "things")
tabTwo = TabPanel(notebook)
notebook.AddPage(tabTwo, "other things")
sizer = wx.BoxSizer(400)
sizer.Add(notebook)
panel.SetSizer(sizer)
#menu bar
status=self.CreateStatusBar()
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
first.Append(wx.NewId(),"New","Creates A new file")
first.Append(wx.NewId(),"ADID","Yo")
menubar.Append(first,"File")
menubar.Append(second,"Edit")
self.SetMenuBar(menubar)
self.Layout()
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = DemoFrame()
app.MainLoop()
Thank you very so much for looking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的操作:
取消注释按钮以查看如何添加更多内容。您可能会在我的代码中找到一些对 wxPython 编程有用的提示。我懒得描述一切;-)。
Try something like this:
Uncomment the buttons to see how you can add more stuff. You may find some useful hints for your wxPython programming in my code. I am to lazy to describe everything ;-).