2013-11-04 66 views
0

WORKS ON(Linux Mint,Python 2.7.5,wxPython 2.8.12.1(gtk2-unicode)),但與Windows 7不兼容。Windows中的其他人可以嘗試嗎?wxPython - 無法按下按鈕或移動滑塊

我用wxPython創建了一個很棒的圖形用戶界面。但是,按鈕和滑塊在其中一個面板中不起作用。請爲我提供一些指導。 (代碼運行正常,但按鈕無法被按下,並不能移動滑塊)

import wx 

class MainWindow(wx.Frame): 

    def __init__(self, *args, **kwargs): 
     super(MainWindow, self).__init__(*args, **kwargs) 

     self.InitUI() 

    def InitUI(self): 
     self.SetSize((1300, 700)) 
     self.SetTitle('GUI made by James') 

     self.panel = wx.Panel(self) 
     self.panel.SetBackgroundColour('#4f5049') 
     mainPanel = wx.Panel(self.panel) 
     mainPanel.SetBackgroundColour('#ededed') 

     sub_vbox = wx.BoxSizer(wx.VERTICAL) 
     subPanel_top = wx.Panel(mainPanel) 

     hbox = wx.BoxSizer(wx.HORIZONTAL) 
     hierarchy_browser = wx.TextCtrl(subPanel_top, style = wx.TE_MULTILINE) 
     hbox.Add(hierarchy_browser, proportion = 1, flag = wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND, border = 10) 
     subPanel_right = wx.Panel(mainPanel) 
     wx.StaticText(subPanel_right, -1, "This is custom static text", (10, 10), (300, -1), wx.ALIGN_CENTER) 
     button = wx.Button(subPanel_right, label = "exit", pos = (500, 100), size = (60, 60)) #can't press for some reason 
     slider = wx.Slider(subPanel_right, -1, 50, 1, 100, pos = (320, 10), size = (250, -1), style = wx.SL_AUTOTICKS | wx.SL_LABELS) # can't slide for some reason 
     slider.SetTickFreq(5, 1) 

     hbox.Add(subPanel_right, proportion = 1, flag = wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND, border = 10) 
     subPanel_top.SetSizer(hbox) 

     sub_vbox.Add(subPanel_top, 1, wx.EXPAND) 

     subPanel_bottom = wx.Panel(mainPanel) 
     text_entry = wx.TextCtrl(subPanel_bottom, style = wx.TE_MULTILINE) 
     text_sizer = wx.BoxSizer() # use sizer to expand TextCtrl 
     text_sizer.Add(text_entry, 1, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 10) 
     subPanel_bottom.SetSizerAndFit(text_sizer) 
     sub_vbox.Add(subPanel_bottom, 1, wx.EXPAND) 
     mainPanel.SetSizer(sub_vbox) 

     vbox = wx.BoxSizer(wx.VERTICAL) 
     vbox.Add(mainPanel, 1, wx.EXPAND | wx.ALL, 10) 
     self.panel.SetSizer(vbox) 

     self.Bind(wx.EVT_BUTTON, self.closebutton, button) 
     self.Bind(wx.EVT_CLOSE, self.closewindow) 

     self.Centre() 
     self.Show(True) 

    def closebutton(self, event): 
     self.Close(True) 

    def closewindow(self, event): 
     self.Destroy() 

def main(): 
    ex = wx.App() 
    MainWindow(None) 
    ex.MainLoop()  

if __name__ == '__main__': 
    main() 
+0

您的代碼適合我。我可以按下按鈕並關閉窗口。我也可以移動滑塊。 (Linux Mint,Python 2.7.5,wxPython 2.8.12.1(gtk2-unicode)) – furas

+0

什麼!?我正在使用Windows。不知道我該如何測試 –

+0

Windows 8,7,Vista,XP或2000?您可以使用命令'python -V'(大寫字母「V」)獲得Python版本。 wxPython版本,你可以通過腳本'import wx; wx.version()' – furas

回答

0

您subPanel_right沒有大小,因爲你根本附着物它,而不是用分級機......所以當篩分器它是在調整大小它的大小是沒有的,你不能點擊

一種解決方案是設置在面板的尺寸

subPanel_right = wx.Panel(subPanel_top,-1,size=(560,300)) 

,你可能需要做服用點搞笑後,做

subPanel_right.SetMinSize(560,300) 

,迫使它是大小,而不是調整(我不知道它的工作對我來說沒有這一點,但有時我不得不這樣做)

一般來說,你不應該混用儀控佈局絕對佈局.. ..例如與flexgridbagsizer一個面板可能已經足夠...或一個面板與一些棘手boxlayouts

+0

它的工作原理沒有任何大小 –

+1

所以關鍵是使用subPanel_top面板,而不是mainPanel –