【问题标题】:The result data in the second frame(panel) doesn't appear exactly第二帧(面板)中的结果数据不完全显示
【发布时间】:2016-11-16 11:45:13
【问题描述】:

为什么我想在第二个面板中显示的数据没有准确显示? 该复选框不是“可检查的”。

如果你尝试全部运行代码,你就会明白我的意思了。

import wx
from wx.lib.pubsub import Publisher
import sys

reload(sys)
sys.setdefaultencoding('cp1252')

########################################################################
class OtherFrame(wx.Frame):

    #----------------------------------------------------------------------
   def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Secondary Frame for showing ResulT",size=(400,400))
        self.panel = OtherPanel(self)


class OtherPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.frame = parent

########################################################################
class MainPanel(wx.Panel):
    #----------------------------------------------------------------------
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.frame = parent


        self.postal_code = wx.TextCtrl(self, value="")
        self.limit = wx.TextCtrl(self,value="")
        showSecondFrame = wx.Button(self, label="Catching")
        showSecondFrame.Bind(wx.EVT_BUTTON, self.ShowFrame)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.postal_code, 0, wx.ALL|wx.CENTER, 5)
        sizer.Add(self.limit, 0, wx.ALL|wx.CENTER, 10)
        sizer.Add(hideBtn, 0, wx.ALL|wx.CENTER, 5)
        self.SetSizer(sizer)

    #----------------------------------------------------------------------
    def ShowFrame(self, event):
        postal_code = self.postal_code.GetValue()
        limit = self.limit.GetValue() 
        new_frame = OtherFrame()
        new_frame.Show()
        print limit, postal_code
        Y = 10
        i=0
        all_data = ['Far Away 1337','Street Dance 101','Necro Lover 152','N0stalgene 689']
        for address in all_data:
            Y += 20
            i += 1

            self.cb = wx.CheckBox(new_frame, label=str(address+"-"+postal_code+"-"+limit), pos=(10,Y))


########################################################################
class MainFrame(wx.Frame):
    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "TEST1NG")
        self.panel = MainPanel(self)
        self.new_frame = OtherFrame()


#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    frame = MainFrame()
    frame.Show()
    app.MainLoop()

【问题讨论】:

    标签: python wxpython wxwidgets


    【解决方案1】:

    发生这种情况是因为您的复选框没有正确的父级。它们被分配给框架,而不是框架上的面板。 在创建复选框时,请尝试这样做

    self.cb = wx.CheckBox(new_frame.panel, label=str(address + "-" + postal_code + "-" + limit), pos=(10, Y))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 2014-03-16
      • 1970-01-01
      • 2017-12-05
      相关资源
      最近更新 更多