การตั้งค่าคลาสอื่นเป็นพาเรนต์ QPushButton [ซ้ำกัน]

ฉันกำลังพยายามสร้างปุ่มจากข้อมูลที่ฉันได้รับจากไฟล์ txt และฉันต้องสร้างปุ่มแต่ละปุ่มในคลาส (ปุ่ม) ที่แตกต่างกัน เนื่องจากโค้ดที่จะดำเนินการจะถูกตั้งค่าเป็นปุ่มสุดท้ายที่โหลดสำหรับปุ่มทั้งหมด แต่เมื่อฉันสร้างปุ่มและตั้งค่าพาเรนต์เป็น GUI id ขัดข้องและบอกว่า Window ไม่ได้ถูกกำหนด แม้ว่าจะถูกสร้างขึ้นก่อนที่ฉันจะสร้างปุ่มก็ตาม และแม้แต่ IDE ของฉันก็ไม่ได้บอกว่า GUI ไม่ได้ใช้ (ฉันลองโดยไม่ตั้งค่าสไตล์ชีต) ** แก้ไข: ** ไฟล์ txt ของฉัน: ชื่อคือ paths.txt

/home/martin/Documents/Zabava/Hry/Eu4_v1.25.1/start.sh$$None$$Europa Universalis 4

/home/martin/TeamSpeak3-Client-linux_amd64/ts3client_runscript.sh$$None$$TeamSpeak 3

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 25 22:08:45 2018

@author: martin
"""


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#Created on Sat Aug 25 17:24:33 2018
import sys
from PyQt4 import QtGui, QtCore
from subprocess import call

paths=[]
class window(QtGui.QMainWindow):
    def __init__(self):
        super(window,self).__init__()
        self.setGeometry(50,50,500,500)
        self.setWindowTitle(".sh Launcher")
        self.setWindowIcon(QtGui.QIcon("Icons/icon.png"))

        menu_add_app=QtGui.QAction("Add Application",self)
        menu_add_app.setShortcut("Ctrl+A")
        menu_add_app.triggered.connect(self.add_app)

        menu_quit_app=QtGui.QAction("Quit",self)
        menu_quit_app.setShortcut("Ctrl+Q")
        menu_quit_app.triggered.connect(self.quit_app)


        main_menu=self.menuBar()
        menu=main_menu.addMenu("Menu")
        menu.addAction(menu_add_app)
        menu.addAction(menu_quit_app)
        self.home()
    def build_apps(self):
        global paths
        print(len(paths))
        for i in range(len(paths)):
            self.data=paths[i]
            if self.data[1]=="None":
                self.data[1]=="Icons/icon.png"
            self.data.append(i)
            buttons(self.data)      
    def home(self):
        self.build_apps()
        #button_add = QtGui.QPushButton("Add Application",self)
        #button_add.clicked.connect(self.add_app)
        #button_quit=QtGui.QPushButton("Quit",self)
        #button_quit.clicked.connect(self.quit_app)


        #button_quit.move(110,0)
        self.show()
    def add_app(self):
        pass
    def quit_app(self):
        sys.exit()
class buttons():
    def __init__(self,data):
        super(buttons,self).__init__()
        self.data=data
        self.path=self.data[0]
        self.icon=QtGui.QIcon(self.data[1])
        self.text=self.data[2]
        self.pos=self.data[3]
        self.button=QtGui.QPushButton(self.icon,self.text,GUI) #I am setting GUI as the parrent
        self.button.clicked.connect(self.execute)
        self.button.move(0,self.pos*25+30)
        self.button.resize(500,25)    
    def execute(self):
        call(self.path)
def load_apps():
    global paths
    f=open("paths.txt","r")
    data=f.readlines()
    for i in range(len(data)):    
        paths.append(data[i].split("$$"))

app=QtGui.QApplication(sys.argv)
app.setStyle("plastique")
try:
    load_apps()
except:
    print("error")
GUI=window() #Here I create the GUI 
GUI.setStyleSheet("QPushButton {text-align:center;outline:0;margin-top:10,}")
sys.exit(app.exec_())

person Martin Pavelka    schedule 25.08.2018    source แหล่งที่มา
comment
เปลี่ยนเป็น print(window) หรือ print(GUI)   -  person eyllanesc    schedule 25.08.2018
comment
ใน python ตัวพิมพ์ใหญ่และตัวพิมพ์เล็กจะแตกต่างกัน   -  person eyllanesc    schedule 25.08.2018
comment
@eyllanesc โอ้ขอโทษที่ฉันเปลี่ยนรหัสที่นี่และลืมลบมัน (ที่ไม่ควรจะอยู่ที่นั่นซึ่งไม่ก่อให้เกิดข้อผิดพลาด)   -  person Martin Pavelka    schedule 25.08.2018
comment
ฉันได้รับหน้าต่างว่าง เห็นได้ชัดว่าฉันไม่มีไฟล์ .txt   -  person eyllanesc    schedule 25.08.2018
comment
เปลี่ยน buttons(self.data) เป็น buttons(self.data, self), เปลี่ยน class buttons(): def __init__(self, data): เป็น class buttons(): def __init__(self, data, parent):, เปลี่ยน self.button = QtGui.QPushButton(self.icon,self.text, parent) เป็น self.button = QtGui.QPushButton(self.icon,self.text)   -  person eyllanesc    schedule 25.08.2018
comment
GUI มีอยู่หลังจากที่ Constructor เสร็จสิ้น ในกรณีของคุณคุณเรียกปุ่มต่างๆ ในตัว Constructor ดังนั้นจึงไม่มีอยู่ ฉันขอแนะนำให้อ่านเกี่ยวกับ OOP   -  person eyllanesc    schedule 25.08.2018
comment
ตอนนี้มันใช้งานได้แล้ว ขอบคุณ.   -  person Martin Pavelka    schedule 25.08.2018