wxPython SetMinSize 问题 [英] wxPython SetMinSize problem

查看:23
本文介绍了wxPython SetMinSize 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在 wxPython 中设置 SetMinSize 时出现问题.有人可以帮我让这个窗口不比启动时小吗?和/或使窗口不允许调整大小?


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?

我在 MainPanel 类中的 self.SetSizerAndFit(SizerH) 之后尝试了 self.SetMinSize(GetSize()).没用.

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?

感谢任何帮助.=]

代码如下:

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

推荐答案

修复:

###---- SHOW THE WINDOW
self.Show(True)
self.SetMinSize(self.GetSize())

一般评论:

代码还不错.只是一些评论:

The code is not bad. Just a few comments:

  • 为小部件使用对象属性,这样您就不会丢失它们的踪迹 (self.ChooseRoot =...)
  • 使用更具描述性的小部件名称 (self.labelChooseRoot)
  • 丢弃 ID,当不需要时,-1 为默认值
  • 删除不提供任何新信息的冗余注释 (self.CreateStatusBar() # Creates statusbar)
  • 您可以从调用 self.Show(True)self.Close(True) 中删除 True 值,因为 True 是默认值
  • 我建议将这种构造函数用于派生的小部件类,但这来自我个人的喜好:
  • use object properties for the widgets, so you do not loose track of them (self.ChooseRoot =...)
  • use more desriptive widget names (self.labelChooseRoot)
  • drop IDs, when not needed, -1 is default value
  • drop redundant comments not giving any new information (self.CreateStatusBar() # Creates statusbar)
  • You can drop True value from calls self.Show(True) and self.Close(True), as True is default value
  • I would recommend using this kind of constructor for derived widget classes, but that comes from my personal preference:

.

def __init__(self, *args, **kwargs):
    wx.Frame.__init__(self, *args, **kwargs)

这篇关于wxPython SetMinSize 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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