Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图从wxpython中的另一个类访问列表时遇到AttributeError_Python_User Interface_Wxpython - Fatal编程技术网

试图从wxpython中的另一个类访问列表时遇到AttributeError

试图从wxpython中的另一个类访问列表时遇到AttributeError,python,user-interface,wxpython,Python,User Interface,Wxpython,我有以下代码: import wx import pandas as pd import pickle from runpy import run_path ######################################################################## class Prototype(wx.Frame): #-------------------------------------------------------------------

我有以下代码:

import wx
import pandas as pd
import pickle
from runpy import run_path

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

 #----------------------------------------------------------------------
 def __init__(self, parent, title):
      wx.Frame.__init__(self, None, title="Tennis Form", size=(800,600))
      self.UI()
      self.Centre()
      self.Show()

 #----------------------------------------------------------------------
 def UI(self):
      _icon = wx.NullIcon
      _icon.CopyFromBitmap(wx.Bitmap("C:\\Users\\XXX\\Desktop\\Project-Tennis\\Tennis-icon.png", wx.BITMAP_TYPE_ANY))
      self.SetIcon(_icon)
      self.SetBackgroundColour(wx.Colour(192, 192, 192))
      self.button_1 = wx.Button(self, wx.ID_ANY, "ATP")
      self.button_1.SetMinSize((250, 50))
      self.button_1.SetBackgroundColour(wx.Colour(216, 216, 191))
      self.button_2 = wx.Button(self, wx.ID_ANY, "WTA")
      self.button_2.SetMinSize((250, 50))
      self.button_2.SetBackgroundColour(wx.Colour(216, 216, 191))
      self.button_2.SetForegroundColour(wx.Colour(0, 0, 0))
      self.button_3 = wx.Button(self, wx.ID_ANY, "Update ATP")
      self.button_3.SetBackgroundColour(wx.Colour(216, 216, 191))
      self.button_3.SetForegroundColour(wx.Colour(0, 0, 0))
      self.button_4 = wx.Button(self, wx.ID_ANY, "Update WTA")
      self.button_4.SetBackgroundColour(wx.Colour(216, 216, 191))
      self.button_4.SetForegroundColour(wx.Colour(0, 0, 0))
      sizer_1 = wx.BoxSizer(wx.VERTICAL)
      sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
      sizer_1.Add((20, 200), 0, 0, 0)
      sizer_1.Add(self.button_1, 0, wx.ALIGN_CENTER | wx.EXPAND | wx.LEFT | wx.RIGHT, 163)
      sizer_1.Add((20, 20), 0, 0, 0)
      sizer_1.Add(self.button_2, 0, wx.ALIGN_CENTER | wx.EXPAND | wx.LEFT | wx.RIGHT, 163)
      sizer_1.Add((20, 180), 0, 0, 0)
      sizer_2.Add((550, 20), 0, 0, 0)
      sizer_2.Add(self.button_3, 0, 0, 0)
      sizer_2.Add(self.button_4, 0, 0, 0)
      sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
      self.SetSizer(sizer_1)
      self.Layout()
      self.Centre()
      self.button_1.Bind(wx.EVT_BUTTON, self.OnButton1)
      self.button_2.Bind(wx.EVT_BUTTON, self.OnButton2)
      self.button_3.Bind(wx.EVT_BUTTON, self.OnButton3)
      self.button_4.Bind(wx.EVT_BUTTON, self.OnButton4)


 #----------------------------------------------------------------------
 def OnButton1(self, event):
      df = pd.read_pickle('C:/Users/XXX/Desktop/Project-Tennis/ATP_Rankings.pickle')
      self.my_list = df["Name"].tolist()
      frame = SecondFrame()
      frame.Show()

 def OnButton2(self, event):
      df = pd.read_pickle('C:/Users/XXX/Desktop/Project-Tennis/WTA_Rankings.pickle')
      self.my_list = df["Name"].tolist()
      frame = SecondFrame()
      frame.Show()

 def OnButton3(self, event):
      settings = run_path("C:/Users/XXX/Desktop/Project-Tennis/ATP-rankings-BS4.py")

 def OnButton4(self, event):
      settings = run_path("C:/Users/XXX/Desktop/Project-Tennis/WTA-rankings-BS4.py")

 ########################################################################
 class SecondFrame(wx.Frame):
 """"""

 #----------------------------------------------------------------------
 def __init__(self):
      """Constructor"""
      wx.Frame.__init__(self, None, title="Select Player", size=(800,600))
      panel = wx.Panel(self)
      self.Centre()
      self.UI()

 def UI(self):
      _icon = wx.NullIcon
      _icon.CopyFromBitmap(wx.Bitmap("C:\\Users\\XXX\\Desktop\\Project-Tennis\\Tennis-icon.png", wx.BITMAP_TYPE_ANY))
      self.SetIcon(_icon)
      self.SetBackgroundColour(wx.Colour(192, 192, 192))
      list1 = Prototype.my_list
      self.combo_box_1 = wx.ComboBox(self, wx.ID_ANY, choices = list1  , style=wx.CB_DROPDOWN | wx.CB_SORT)
      self.combo_box_2 = wx.ComboBox(self, wx.ID_ANY, choices=[], style=wx.CB_DROPDOWN | wx.CB_SORT)
      self.Run = wx.Button(self, wx.ID_ANY, "Run")
      self.Run.SetMinSize((150, 35))
      self.Run.SetBackgroundColour(wx.Colour(216, 216, 191))
      self.Run.SetForegroundColour(wx.Colour(0, 0, 0))
      self.combo_box_1.SetMinSize((450, 50))
      self.combo_box_2.SetMinSize((450, 50))
      sizer_1 = wx.BoxSizer(wx.VERTICAL)
      sizer_1.Add((20, 200), 0, 0, 0)
      sizer_1.Add(self.combo_box_1, 0, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, 0)
      sizer_1.Add((20, 20), 0, 0, 0)
      sizer_1.Add(self.combo_box_2, 0, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, 0)
      sizer_1.Add((20, 25), 0, 0, 0)
      sizer_1.Add(self.Run, 0, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, 0)
      self.SetSizer(sizer_1)
      self.Layout()
      self.Centre()


app = wx.App(False)
Prototype(None, title='')
app.MainLoop()
我试过wxpython和PyQt5,但最终还是在同一点上卡住了

我想使用在按下主窗口(原型)上的两个按钮之一时创建的列表,将其放入我在第二帧上创建的组合框中

但是,我总是得到AttributeError:Type对象“Prototype”没有属性“my_list”


当按下一个按钮并使用第二帧SecondFrame中的列表时,应该如何访问在主窗口原型中创建的“我的列表”?

。我的列表是一个实例属性,而不是类属性。您必须将列表传递给您的
SecondFrame
类构造函数:

class SecondFrame(wx.Frame):
    def __init__(self, the_list):
        wx.Frame.__init__(self, None, title="Select Player", size=(800,600)) 
        self.my_list = the_list
        # ...


    def UI(self):
        # ...
        self.combo_box_1 = wx.ComboBox(self, wx.ID_ANY, choices=self.my_list, style=wx.CB_DROPDOWN | wx.CB_SORT)


class Prototype(wx.Frame):
    # ....
    def OnButton1(self, event):
      df = pd.read_pickle('C:/Users/XXX/Desktop/Project-Tennis/ATP_Rankings.pickle')
      self.my_list = df["Name"].tolist()
      frame = SecondFrame(self.my_list)
      frame.Show()