pyside6 两个页面互相跳转

kuka示教器嵌套UR界面操作ros中rviz的UR机器人-CSDN博客

接上一篇,探索了两个页面互相跳转的操作。

1.两个页面

页面:UrWin,主要显示Ur机器人的VNC远程控制界面

页面:ZcWin,主要是选择插针的长度

 在Ur远程界面点击下一步会跳转到针选择界面,在针选择界面点击上一步按钮会跳转到Ur远程界面。而且只保留一个界面。原界面会非销毁掉。

2.界面实现的代码

ur界面参考上一篇博客,针选择界面也是类似的操作一遍即可

2.1 针选择界面

pyside6-uic zhen_choose.ui -o ui_zhen_choose.py

 

 

# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'zhen_choose.ui'
##
## Created by: Qt User Interface Compiler version 6.6.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
    QMetaObject, QObject, QPoint, QRect,
    QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
    QFont, QFontDatabase, QGradient, QIcon,
    QImage, QKeySequence, QLinearGradient, QPainter,
    QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QPushButton, QSizePolicy,
    QWidget)

class Ui_Zhen_choose(object):
    def setupUi(self, Zhen_choose):
        if not Zhen_choose.objectName():
            Zhen_choose.setObjectName(u"Zhen_choose")
        Zhen_choose.resize(1050, 747)
        Zhen_choose.setStyleSheet(u"background-image: url(:/kuka_top.png);")
        self.label = QLabel(Zhen_choose)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(370, 320, 101, 17))
        self.label_2 = QLabel(Zhen_choose)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(370, 350, 101, 17))
        self.label_3 = QLabel(Zhen_choose)
        self.label_3.setObjectName(u"label_3")
        self.label_3.setGeometry(QRect(370, 380, 101, 17))
        self.Bt_lastone = QPushButton(Zhen_choose)
        self.Bt_lastone.setObjectName(u"Bt_lastone")
        self.Bt_lastone.setGeometry(QRect(500, 570, 89, 25))

        self.retranslateUi(Zhen_choose)

        QMetaObject.connectSlotsByName(Zhen_choose)
    # setupUi

    def retranslateUi(self, Zhen_choose):
        Zhen_choose.setWindowTitle(QCoreApplication.translate("Zhen_choose", u"\u9009\u62e9\u9488", None))
        self.label.setText(QCoreApplication.translate("Zhen_choose", u"\u94881\uff1a50mm", None))
        self.label_2.setText(QCoreApplication.translate("Zhen_choose", u"\u94882\uff1a60mm", None))
        self.label_3.setText(QCoreApplication.translate("Zhen_choose", u"\u94881\uff1a80mm", None))
        self.Bt_lastone.setText(QCoreApplication.translate("Zhen_choose", u"\u4e0a\u4e00\u6b65", None))
    # retranslateUi

2.1 Ur界面 

 

# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'urVnc.ui'
##
## Created by: Qt User Interface Compiler version 6.6.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
    QMetaObject, QObject, QPoint, QRect,
    QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
    QFont, QFontDatabase, QGradient, QIcon,
    QImage, QKeySequence, QLinearGradient, QPainter,
    QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QPushButton, QSizePolicy, QWidget)

from PySide6.QtWebEngineWidgets import QWebEngineView
#from QtWebKitWidgets.QWebView import QWebView

class Ui_urVNC(object):
    def setupUi(self, urVNC):
        if not urVNC.objectName():
            urVNC.setObjectName(u"urVNC")
        urVNC.resize(1056, 750)
        urVNC.setStyleSheet(u"background-image: url(:/kuka_top.png);")
        self.Bt_next = QPushButton(urVNC)
        self.Bt_next.setObjectName(u"Bt_next")
        self.Bt_next.setGeometry(QRect(710, 570, 89, 25))
        self.webView = QWebEngineView(urVNC)
        self.webView.setObjectName(u"webView")
        self.webView.setGeometry(QRect(230, 190, 601, 371))
        self.webView.setUrl(QUrl(u"http://192.168.56.101:6080/vnc.html"))
        self.webView.setZoomFactor(0.500000000000000)
        self.Bt_lastone = QPushButton(urVNC)
        self.Bt_lastone.setObjectName(u"Bt_lastone")
        self.Bt_lastone.setGeometry(QRect(580, 570, 89, 25))

        self.retranslateUi(urVNC)

        QMetaObject.connectSlotsByName(urVNC)
    # setupUi

    def retranslateUi(self, urVNC):
        urVNC.setWindowTitle(QCoreApplication.translate("urVNC", u"UR VNC", None))
        self.Bt_next.setText(QCoreApplication.translate("urVNC", u"\u4e0b\u4e00\u6b65", None))
        self.Bt_lastone.setText(QCoreApplication.translate("urVNC", u"\u4e0a\u4e00\u6b65", None))
    # retranslateUi

3.主程序

      这个实现主要是在主程序里面增加几行代码即可,如下图所示,给相关的按钮赋予点击操作,操作函数显示窗口和关闭窗口。

     

    相关按钮的名字可以在相关ui的python文件中找。如下图,这些名字就是这么一 一对应,选择调用即可。

 

# This Python file uses the following encoding: utf-8

# if __name__ == "__main__":
#     pass

import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
from PySide6.QtCore import QFile
from ui_urVnc import Ui_urVNC
from ui_zhen_choose import Ui_Zhen_choose
import images

class UrWin(QMainWindow):
    def __init__(self):
        super(UrWin, self).__init__()
        self.ui = Ui_urVNC()
        self.ui.setupUi(self)
        self.ui.Bt_next.clicked.connect(self.show_ZcWin)

    def show_ZcWin(self, checked):
        print("dian ji")
        self.w = ZcWin()
        self.w.show()
        self.close()


class ZcWin(QMainWindow):
    def __init__(self):
        super(ZcWin, self).__init__()
        self.ui = Ui_Zhen_choose()
        self.ui.setupUi(self)
        self.ui.Bt_lastone.clicked.connect(self.show_urvnc)
    def show_urvnc(self,checked):
        self.win_urvnc = UrWin()
        self.win_urvnc.show()
        self.close()


if __name__ == "__main__":
    app = QApplication(sys.argv)

    window = UrWin()
    window.show()

    sys.exit(app.exec())

 4.运行测试

所需要的文件放到一个文件里面就可以了,

就是这些文件,就可以正常的运行了

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在使用 PySide6 开发页面跳转时,你可以通过以下步骤实现: 1. 首先,导入所需的模块: ```python from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QHBoxLayout, QVBoxLayout, QWidget ``` 2. 创建一个继承自 QMainWindow 的主窗口类,用于管理页面的切换: ```python class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Page Navigation Example") self.stack = QWidget(self) self.setCentralWidget(self.stack) self.layout = QVBoxLayout(self.stack) self.showPage1() def showPage1(self): self.page1 = QWidget() self.page1_layout = QVBoxLayout(self.page1) self.label1 = QLabel("Page 1") self.page1_layout.addWidget(self.label1) self.button1 = QPushButton("Go to Page 2") self.button1.clicked.connect(self.showPage2) self.page1_layout.addWidget(self.button1) self.layout.addWidget(self.page1) def showPage2(self): self.page2 = QWidget() self.page2_layout = QVBoxLayout(self.page2) self.label2 = QLabel("Page 2") self.page2_layout.addWidget(self.label2) self.button2 = QPushButton("Go to Page 1") self.button2.clicked.connect(self.showPage1) self.page2_layout.addWidget(self.button2) self.layout.addWidget(self.page2) ``` 3. 创建 QApplication 实例,并显示主窗口: ```python app = QApplication([]) window = MainWindow() window.show() app.exec() ``` 在上述代码中,我们通过创建多个 QWidget 页面,并使用 QVBoxLayout 将它们添加到主窗口的布局中。每个页面都包含一个 QPushButton,用于触发页面切换的槽函数。通过单击按钮,我们可以在两个页面之间进行切换。 注意:这只是一个简单的示例,可以根据实际需求进行扩展和修改。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leecheni

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值