简体   繁体   中英

Opening new window in pyqt4

I've been trying to create GUI using PyQt4. I don't really have much experience using PyQt4 or OOP.

I would like to have a main window which would be able to plot some graphs but also have some buttons, which would open new windows.

From multiple tutorials I've gathered this code:

from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure



class Window1(QtGui.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()




class Window(QtGui.QDialog):
    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 800, 600)
        self.setWindowTitle("App")


        self.figure = Figure()
        self.button = QtGui.QPushButton('Plot')
        self.button.clicked.connect(self.plot)
        self.button1 = QtGui.QPushButton('Count')
        self.button1.clicked.connect(self.show_count)
        self.count = Window1(self)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        layout.addWidget(self.button)
        layout.addWidget(self.button1)

    def plot(self): #some random stuff for now
        list1 = [3,4,5,6,9,12]
        list2 = [8,12,14,15,17,20]



        ax = self.figure.add_subplot(111)


        ax.clear()


        ax.plot(list1, list2)

        self.canvas.draw()  

    def show_count(self):
        self.count.show()

First of all, I keep getting this error: TypeError: init () takes 1 positional argument but 2 were given

Secondly, is there any way to print some kind of a table in new window, where some elements of a list would be shown?

to show table :

QTableWidget

The QTableWidget class provides an item-based table view with a default model.

Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem

For your error:

TypeError: init() takes 1 positional argument but 2 were given

Instead of

self.count = Window1(self)

use:

self.count = Window1()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM