wxPython SetMinSize问题
在 wxPython 中设置 SetMinSize 时遇到问题。有人可以帮我让这个窗口不比启动时小吗?和/或使窗口不允许调整大小?
我在 MainPanel 类中的 self.SetSizerAndFit(SizerH)
之后尝试了 self.SetMinSize(GetSize())
。没有工作。
我已经查看并搜索过,但没有任何帮助。
我也是编程新手,有人可以评论一下程序是如何构建的吗?是不是可以理解并且很好呢?或者应该采取什么措施?
感谢任何帮助。 =]
继承代码:
import wx
ID_EXIT = 110
class MainPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.parent = parent
#------------- Setting up the buttons
Run = wx.Button(self, label="Run")
Run.Bind(wx.EVT_BUTTON, self.Run )
#------------- Setting up Static text
ChooseRoot = wx.StaticText(self, label ="Root catalog: ")
ScratchWrk = wx.StaticText(self, label ="Sratch workspace: ")
MergeFile = wx.StaticText(self, label ="Merge file: ")
#------------ Setting up inputtext
ChooseRootTxt = wx.TextCtrl(self, -1, size=(210,-1))
#------------- Setting up the outputbox
Output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
#------------- Setting up the sizer
SizerV1 = wx.BoxSizer(wx.VERTICAL)
SizerV1.Add(ChooseRoot, 0,wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV1.Add(ScratchWrk, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV1.Add(MergeFile, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV3 = wx.BoxSizer(wx.VERTICAL)
SizerV3.Add(ChooseRootTxt, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV2 = wx.BoxSizer(wx.VERTICAL)
SizerV2.Add(Run, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerH1 = wx.BoxSizer()
SizerH1.Add(SizerV1, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH1.Add(SizerV3, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH1.Add(SizerV2, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH2 = wx.BoxSizer()
SizerH2.Add(Output, 1, wx.EXPAND | wx.ALL, 5)
SizerH = wx.BoxSizer(wx.VERTICAL)
SizerH.Add(SizerH1, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH.Add(SizerH2, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
self.SetSizerAndFit(SizerH)
#--- START EVENT HANDLERS
def Run(self, event=None):
pass
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size = (415,330),
style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE | wx.STAY_ON_TOP)
self.CreateStatusBar() # Creates statusbar
#------------- Setting up the menu
filemenu = wx.Menu()
filemenu.Append(ID_EXIT, "E&xit", "Exit the program")
#------------- Creating the menu
menubar = wx.MenuBar()
menubar.Append(filemenu, "&File")
self.SetMenuBar(menubar)
#---------- Setting menu event handlers
wx.EVT_MENU(self, ID_EXIT, self.OnExit)
#--- Add MainPanel
self.Panel = MainPanel(self, -1)
#Centre on Screen
self.CentreOnScreen()
###---- SHOW THE WINDOW
self.Show(True)
def OnExit(self, event):
self.Close(True) # Close the Frame
#--- END EVENT HANDLERS ---------------------------------
if __name__=='__main__':
try:
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Indexinator3000")
app.MainLoop()
finally:
del app
Having problems setting the SetMinSize in wxPython. Can someone please help me getting this window not getting any smaller than it is in the startup? And/or making the window not allowing resize?
I tried self.SetMinSize(GetSize())
after self.SetSizerAndFit(SizerH)
in the MainPanel class. Did not work.
I've looked and searched but to no help.
Im also new to programming and can someone also comment on how the program is built up? Is it understandable and good? Or should measures be taken?
Appreciate any help. =]
Heres the code:
import wx
ID_EXIT = 110
class MainPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.parent = parent
#------------- Setting up the buttons
Run = wx.Button(self, label="Run")
Run.Bind(wx.EVT_BUTTON, self.Run )
#------------- Setting up Static text
ChooseRoot = wx.StaticText(self, label ="Root catalog: ")
ScratchWrk = wx.StaticText(self, label ="Sratch workspace: ")
MergeFile = wx.StaticText(self, label ="Merge file: ")
#------------ Setting up inputtext
ChooseRootTxt = wx.TextCtrl(self, -1, size=(210,-1))
#------------- Setting up the outputbox
Output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
#------------- Setting up the sizer
SizerV1 = wx.BoxSizer(wx.VERTICAL)
SizerV1.Add(ChooseRoot, 0,wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV1.Add(ScratchWrk, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV1.Add(MergeFile, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV3 = wx.BoxSizer(wx.VERTICAL)
SizerV3.Add(ChooseRootTxt, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerV2 = wx.BoxSizer(wx.VERTICAL)
SizerV2.Add(Run, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
SizerH1 = wx.BoxSizer()
SizerH1.Add(SizerV1, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH1.Add(SizerV3, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH1.Add(SizerV2, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH2 = wx.BoxSizer()
SizerH2.Add(Output, 1, wx.EXPAND | wx.ALL, 5)
SizerH = wx.BoxSizer(wx.VERTICAL)
SizerH.Add(SizerH1, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
SizerH.Add(SizerH2, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL)
self.SetSizerAndFit(SizerH)
#--- START EVENT HANDLERS
def Run(self, event=None):
pass
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size = (415,330),
style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE | wx.STAY_ON_TOP)
self.CreateStatusBar() # Creates statusbar
#------------- Setting up the menu
filemenu = wx.Menu()
filemenu.Append(ID_EXIT, "E&xit", "Exit the program")
#------------- Creating the menu
menubar = wx.MenuBar()
menubar.Append(filemenu, "&File")
self.SetMenuBar(menubar)
#---------- Setting menu event handlers
wx.EVT_MENU(self, ID_EXIT, self.OnExit)
#--- Add MainPanel
self.Panel = MainPanel(self, -1)
#Centre on Screen
self.CentreOnScreen()
###---- SHOW THE WINDOW
self.Show(True)
def OnExit(self, event):
self.Close(True) # Close the Frame
#--- END EVENT HANDLERS ---------------------------------
if __name__=='__main__':
try:
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Indexinator3000")
app.MainLoop()
finally:
del app
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
修复:
一般评论:
代码还不错。只是一些评论:
self.ChooseRoot =...
)self.labelChooseRoot
) code>)self.CreateStatusBar() # Creates statusbar
)self.Show(True)
和self.Close(True)
,因为 True 是默认值,。
Fix:
General comments:
The code is not bad. Just a few comments:
self.ChooseRoot =...
)self.labelChooseRoot
)self.CreateStatusBar() # Creates statusbar
)self.Show(True)
andself.Close(True)
, as True is default value.