小编Sam*_* L.的帖子

如何使用PyQt从另一个窗口单击按钮打开一个窗口?

我正在尝试创建一个应用程序,但我不断被这个"简单"的东西打了一拳,如何通过点击按钮打开一个新窗口?我尝试使用new_lib_btn.clicked.connect(newlib),newlib是包含我的第二个窗口的文件,new_lib_btn是应该打开窗口的按钮,它在我的主窗口中,你可以在这里看到:

mainwindow.py

from PyQt4 import QtCore, QtGui
import newlib
import sys
# Main Window

class Window (QtGui.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        centralwidget = QtGui.QWidget(self)
        self.mainLayout = QtGui.QVBoxLayout(centralwidget)
        self.mainLayout.setAlignment(QtCore.Qt.AlignCenter)
        self.setCentralWidget(centralwidget)

        self.resize(800, 600)
        self.setWindowTitle("Virtual Library")
        self.setStyleSheet("Window {border-image: url(lib.jpg);}")

        # ExitOption
        menu_action1 = QtGui.QAction("Exit", self)
        menu_action1.setShortcut("Ctrl+Q")
        menu_action1.setStatusTip('Exit The App')
        menu_action1.triggered.connect(self.close_application)

        self.statusBar()

        # MenuBar
        main_menu = self.menuBar()
        file_menu = main_menu.addMenu('Options')
        file_menu.addAction(menu_action1)



        self.home()

    def home(self):
        # NewLibrary btn
        new_lib_btn = QtGui.QPushButton("New Library", self)
        new_lib_btn.setGeometry(QtCore.QRect(310, 180, 141, 41))
        new_lib_btn.setStyleSheet("color: black;") …
Run Code Online (Sandbox Code Playgroud)

python window pyqt buttonclick

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

buttonclick ×1

pyqt ×1

python ×1

window ×1