Window 无法在 PyQT5 GUI 中打开
Window not opening inPyQT5 GUI
我正在尝试使用 Pyqt5 创建一个 GUI 应用程序。我面临的问题是代码 运行 很好,但是 record window 没有打开。我附上了下面的整个代码和我所指的函数的片段。我已经尝试过整个代码,但没有发现任何缺陷。
import sys
from random import randint
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget
import time
#from libsonyapi.camera import Camera
#from libsonyapi.actions import Actions
#from pysony import SonyAPI, ControlPoint, common_header
#search = ControlPoint()
#cameras = search.discover(1)
#camera = SonyAPI(QX_ADDR=cameras[0])
# create camera instance
#camerass = Camera()
###############################SECONDARY WINDOWS###############################################################################
class recording(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED TO START RECORDING #
start_recording_button = QPushButton(" START RECORDING ")
start_recording_button.clicked.connect(self.start_recording)
layout.addWidget(start_recording_button)
# THIS BUTTON IS USED TO STOP RECORDING #
stop_recording_button = QPushButton(" STOP RECORDING ")
stop_recording_button.clicked.connect(self.stop_recording)
layout.addWidget(stop_recording_button)
self.show()
def start_recording(self):
camerass.do(Actions.startMovieRec)
time.sleep(2)
def stop_recording(self):
camerass.do(Actions.stopMovieRec)
time.sleep(2)
class zoom(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED AS ZOOM IN #
zoom_in_button = QPushButton(" ZOOM IN ")
zoom_in_button.clicked.connect(self.zoom_in)
layout.addWidget(zoom_in_button)
# THIS BUTTON IS USED AS ZOOM OUT #
zoom_out_button = QPushButton(" ZOOM OUT ")
zoom_out_button.clicked.connect(self.zoom_out)
layout.addWidget(zoom_out_button)
# THIS BUTTON IS USED TO STOP THE ZOOM IN #
stop_zoom_in_button = QPushButton(" STOP ZOOM IN ")
stop_zoom_in_button.clicked.connect(self.stop_zoom_in)
layout.addWidget(stop_zoom_in_button)
# THIS BUTTON IS USED TO STOP THE ZOOM OUT #
stop_zoom_out_button = QPushButton(" STOP ZOOM OUT ")
stop_zoom_out_button.clicked.connect(self.stop_zoom_out)
layout.addWidget(stop_zoom_out_button)
self.show()
def zoom_in(self):
camera.actZoom(param=["in", "start"])
time.sleep(2)
def zoom_out(self):
camera.actZoom(param=["out", "start"])
time.sleep(2)
def stop_zoom_in(self):
camera.actZoom(param=["in", "stop"])
time.sleep(2)
def stop_zoom_out(self):
camera.actZoom(param=["out", "stop"])
time.sleep(2)
################################MAIN WINDOW 1##################################################################################
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
button1 = QPushButton("CAMERA CONTROLS")
button1.clicked.connect(self.open_newWindow)
l.addWidget(button1)
w = QWidget()
w.setLayout(l)
self.setCentralWidget(w)
def open_newWindow(self):
window = MainWindow2()
self.windows.append(window)
window.show()
###########################MAIN WINDOW 3########################################################################################
class MainWindow3(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
zoom_controls_button = QPushButton("RECORDING")
zoom_controls_button.clicked.connect(self.open_newWindow3)
l.addWidget(zoom_controls_button)
s = QWidget()
s.setLayout(l)
self.setCentralWidget(s)
def open_newWindow3(self):
window = recording()
self.windows.append(window)
window.show()
################################MAIN WINDOW 2##################################################################################
class MainWindow2(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
zoom_controls_button = QPushButton("ZOOM CONTROLS")
zoom_controls_button.clicked.connect(self.open_newWindow2)
l.addWidget(zoom_controls_button)
s = QWidget()
s.setLayout(l)
self.setCentralWidget(s)
def open_newWindow2(self):
window = zoom()
self.windows.append(window)
window.show()
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()
函数是
class recording(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED TO START RECORDING #
start_recording_button = QPushButton(" START RECORDING ")
start_recording_button.clicked.connect(self.start_recording)
layout.addWidget(start_recording_button)
# THIS BUTTON IS USED TO STOP RECORDING #
stop_recording_button = QPushButton(" STOP RECORDING ")
stop_recording_button.clicked.connect(self.stop_recording)
layout.addWidget(stop_recording_button)
self.show()
def start_recording(self):
camerass.do(Actions.startMovieRec)
time.sleep(2)
def stop_recording(self):
camerass.do(Actions.stopMovieRec)
time.sleep(2)
在您的代码中,您永远不会创建 MainWindow3,其中将在单击“录制”按钮后创建录制 class / window。
创建 MainWindow3 后,按下按钮后会显示录音 window。
要对此进行测试,您只需替换
w = MainWindow()
和
w = MainWindow3()
在你的“主要”(倒数第三行)
我的系统中有 运行 它并做了一些更改。我正在粘贴下面的代码。
from random import randint
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget
import time
#from libsonyapi.camera import Camera
#from libsonyapi.actions import Actions
#from pysony import SonyAPI, ControlPoint, common_header
#search = ControlPoint()
#cameras = search.discover(1)
#camera = SonyAPI(QX_ADDR=cameras[0])
# create camera instance
#camerass = Camera()
###############################SECONDARY WINDOWS###############################################################################
class recording(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED TO START RECORDING #
start_recording_button = QPushButton(" START RECORDING ")
start_recording_button.clicked.connect(self.start_recording)
layout.addWidget(start_recording_button)
# THIS BUTTON IS USED TO STOP RECORDING #
stop_recording_button = QPushButton(" STOP RECORDING ")
stop_recording_button.clicked.connect(self.stop_recording)
layout.addWidget(stop_recording_button)
self.show()
def start_recording(self):
camerass.do(Actions.startMovieRec)
time.sleep(2)
def stop_recording(self):
camerass.do(Actions.stopMovieRec)
time.sleep(2)
class zoom(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED AS ZOOM IN #
zoom_in_button = QPushButton(" ZOOM IN ")
zoom_in_button.clicked.connect(self.zoom_in)
layout.addWidget(zoom_in_button)
# THIS BUTTON IS USED AS ZOOM OUT #
zoom_out_button = QPushButton(" ZOOM OUT ")
zoom_out_button.clicked.connect(self.zoom_out)
layout.addWidget(zoom_out_button)
# THIS BUTTON IS USED TO STOP THE ZOOM IN #
stop_zoom_in_button = QPushButton(" STOP ZOOM IN ")
stop_zoom_in_button.clicked.connect(self.stop_zoom_in)
layout.addWidget(stop_zoom_in_button)
# THIS BUTTON IS USED TO STOP THE ZOOM OUT #
stop_zoom_out_button = QPushButton(" STOP ZOOM OUT ")
stop_zoom_out_button.clicked.connect(self.stop_zoom_out)
layout.addWidget(stop_zoom_out_button)
self.show()
def zoom_in(self):
camera.actZoom(param=["in", "start"])
time.sleep(2)
def zoom_out(self):
camera.actZoom(param=["out", "start"])
time.sleep(2)
def stop_zoom_in(self):
camera.actZoom(param=["in", "stop"])
time.sleep(2)
def stop_zoom_out(self):
camera.actZoom(param=["out", "stop"])
time.sleep(2)
################################MAIN WINDOW 1##################################################################################
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
camera_controls_button = QPushButton("CAMERA CONTROLS")
camera_controls_button.clicked.connect(self.open_newWindow)
l.addWidget(camera_controls_button)
w = QWidget()
w.setLayout(l)
self.setCentralWidget(w)
def open_newWindow(self):
window = MainWindow2()
self.windows.append(window)
window.show()
################################MAIN WINDOW 2##################################################################################
class MainWindow2(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
zoom_controls_button = QPushButton("ZOOM CONTROLS")
zoom_controls_button.clicked.connect(self.open_newWindow2)
l.addWidget(zoom_controls_button)
record_controls_button = QPushButton("RECORDING")
record_controls_button.clicked.connect(self.open_newWindow3)
l.addWidget(record_controls_button)
s = QWidget()
s.setLayout(l)
self.setCentralWidget(s)
def open_newWindow2(self):
window1 = zoom()
self.windows.append(window1)
window1.show()
def open_newWindow3(self):
window2 = recording()
self.windows.append(window2)
window2.show()
####################END#########################################################################################################
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()
我正在尝试使用 Pyqt5 创建一个 GUI 应用程序。我面临的问题是代码 运行 很好,但是 record window 没有打开。我附上了下面的整个代码和我所指的函数的片段。我已经尝试过整个代码,但没有发现任何缺陷。
import sys
from random import randint
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget
import time
#from libsonyapi.camera import Camera
#from libsonyapi.actions import Actions
#from pysony import SonyAPI, ControlPoint, common_header
#search = ControlPoint()
#cameras = search.discover(1)
#camera = SonyAPI(QX_ADDR=cameras[0])
# create camera instance
#camerass = Camera()
###############################SECONDARY WINDOWS###############################################################################
class recording(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED TO START RECORDING #
start_recording_button = QPushButton(" START RECORDING ")
start_recording_button.clicked.connect(self.start_recording)
layout.addWidget(start_recording_button)
# THIS BUTTON IS USED TO STOP RECORDING #
stop_recording_button = QPushButton(" STOP RECORDING ")
stop_recording_button.clicked.connect(self.stop_recording)
layout.addWidget(stop_recording_button)
self.show()
def start_recording(self):
camerass.do(Actions.startMovieRec)
time.sleep(2)
def stop_recording(self):
camerass.do(Actions.stopMovieRec)
time.sleep(2)
class zoom(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED AS ZOOM IN #
zoom_in_button = QPushButton(" ZOOM IN ")
zoom_in_button.clicked.connect(self.zoom_in)
layout.addWidget(zoom_in_button)
# THIS BUTTON IS USED AS ZOOM OUT #
zoom_out_button = QPushButton(" ZOOM OUT ")
zoom_out_button.clicked.connect(self.zoom_out)
layout.addWidget(zoom_out_button)
# THIS BUTTON IS USED TO STOP THE ZOOM IN #
stop_zoom_in_button = QPushButton(" STOP ZOOM IN ")
stop_zoom_in_button.clicked.connect(self.stop_zoom_in)
layout.addWidget(stop_zoom_in_button)
# THIS BUTTON IS USED TO STOP THE ZOOM OUT #
stop_zoom_out_button = QPushButton(" STOP ZOOM OUT ")
stop_zoom_out_button.clicked.connect(self.stop_zoom_out)
layout.addWidget(stop_zoom_out_button)
self.show()
def zoom_in(self):
camera.actZoom(param=["in", "start"])
time.sleep(2)
def zoom_out(self):
camera.actZoom(param=["out", "start"])
time.sleep(2)
def stop_zoom_in(self):
camera.actZoom(param=["in", "stop"])
time.sleep(2)
def stop_zoom_out(self):
camera.actZoom(param=["out", "stop"])
time.sleep(2)
################################MAIN WINDOW 1##################################################################################
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
button1 = QPushButton("CAMERA CONTROLS")
button1.clicked.connect(self.open_newWindow)
l.addWidget(button1)
w = QWidget()
w.setLayout(l)
self.setCentralWidget(w)
def open_newWindow(self):
window = MainWindow2()
self.windows.append(window)
window.show()
###########################MAIN WINDOW 3########################################################################################
class MainWindow3(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
zoom_controls_button = QPushButton("RECORDING")
zoom_controls_button.clicked.connect(self.open_newWindow3)
l.addWidget(zoom_controls_button)
s = QWidget()
s.setLayout(l)
self.setCentralWidget(s)
def open_newWindow3(self):
window = recording()
self.windows.append(window)
window.show()
################################MAIN WINDOW 2##################################################################################
class MainWindow2(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
zoom_controls_button = QPushButton("ZOOM CONTROLS")
zoom_controls_button.clicked.connect(self.open_newWindow2)
l.addWidget(zoom_controls_button)
s = QWidget()
s.setLayout(l)
self.setCentralWidget(s)
def open_newWindow2(self):
window = zoom()
self.windows.append(window)
window.show()
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()
函数是
class recording(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED TO START RECORDING #
start_recording_button = QPushButton(" START RECORDING ")
start_recording_button.clicked.connect(self.start_recording)
layout.addWidget(start_recording_button)
# THIS BUTTON IS USED TO STOP RECORDING #
stop_recording_button = QPushButton(" STOP RECORDING ")
stop_recording_button.clicked.connect(self.stop_recording)
layout.addWidget(stop_recording_button)
self.show()
def start_recording(self):
camerass.do(Actions.startMovieRec)
time.sleep(2)
def stop_recording(self):
camerass.do(Actions.stopMovieRec)
time.sleep(2)
在您的代码中,您永远不会创建 MainWindow3,其中将在单击“录制”按钮后创建录制 class / window。
创建 MainWindow3 后,按下按钮后会显示录音 window。 要对此进行测试,您只需替换
w = MainWindow()
和
w = MainWindow3()
在你的“主要”(倒数第三行)
我的系统中有 运行 它并做了一些更改。我正在粘贴下面的代码。
from random import randint
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget
import time
#from libsonyapi.camera import Camera
#from libsonyapi.actions import Actions
#from pysony import SonyAPI, ControlPoint, common_header
#search = ControlPoint()
#cameras = search.discover(1)
#camera = SonyAPI(QX_ADDR=cameras[0])
# create camera instance
#camerass = Camera()
###############################SECONDARY WINDOWS###############################################################################
class recording(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED TO START RECORDING #
start_recording_button = QPushButton(" START RECORDING ")
start_recording_button.clicked.connect(self.start_recording)
layout.addWidget(start_recording_button)
# THIS BUTTON IS USED TO STOP RECORDING #
stop_recording_button = QPushButton(" STOP RECORDING ")
stop_recording_button.clicked.connect(self.stop_recording)
layout.addWidget(stop_recording_button)
self.show()
def start_recording(self):
camerass.do(Actions.startMovieRec)
time.sleep(2)
def stop_recording(self):
camerass.do(Actions.stopMovieRec)
time.sleep(2)
class zoom(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout(self)
# THIS BUTTON IS USED AS ZOOM IN #
zoom_in_button = QPushButton(" ZOOM IN ")
zoom_in_button.clicked.connect(self.zoom_in)
layout.addWidget(zoom_in_button)
# THIS BUTTON IS USED AS ZOOM OUT #
zoom_out_button = QPushButton(" ZOOM OUT ")
zoom_out_button.clicked.connect(self.zoom_out)
layout.addWidget(zoom_out_button)
# THIS BUTTON IS USED TO STOP THE ZOOM IN #
stop_zoom_in_button = QPushButton(" STOP ZOOM IN ")
stop_zoom_in_button.clicked.connect(self.stop_zoom_in)
layout.addWidget(stop_zoom_in_button)
# THIS BUTTON IS USED TO STOP THE ZOOM OUT #
stop_zoom_out_button = QPushButton(" STOP ZOOM OUT ")
stop_zoom_out_button.clicked.connect(self.stop_zoom_out)
layout.addWidget(stop_zoom_out_button)
self.show()
def zoom_in(self):
camera.actZoom(param=["in", "start"])
time.sleep(2)
def zoom_out(self):
camera.actZoom(param=["out", "start"])
time.sleep(2)
def stop_zoom_in(self):
camera.actZoom(param=["in", "stop"])
time.sleep(2)
def stop_zoom_out(self):
camera.actZoom(param=["out", "stop"])
time.sleep(2)
################################MAIN WINDOW 1##################################################################################
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
camera_controls_button = QPushButton("CAMERA CONTROLS")
camera_controls_button.clicked.connect(self.open_newWindow)
l.addWidget(camera_controls_button)
w = QWidget()
w.setLayout(l)
self.setCentralWidget(w)
def open_newWindow(self):
window = MainWindow2()
self.windows.append(window)
window.show()
################################MAIN WINDOW 2##################################################################################
class MainWindow2(QMainWindow):
def __init__(self):
super().__init__()
self.windows = []
l = QVBoxLayout()
zoom_controls_button = QPushButton("ZOOM CONTROLS")
zoom_controls_button.clicked.connect(self.open_newWindow2)
l.addWidget(zoom_controls_button)
record_controls_button = QPushButton("RECORDING")
record_controls_button.clicked.connect(self.open_newWindow3)
l.addWidget(record_controls_button)
s = QWidget()
s.setLayout(l)
self.setCentralWidget(s)
def open_newWindow2(self):
window1 = zoom()
self.windows.append(window1)
window1.show()
def open_newWindow3(self):
window2 = recording()
self.windows.append(window2)
window2.show()
####################END#########################################################################################################
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()