Issue with tabs

Heads up! You've already completed this tutorial.

itural869796 | 2021-02-01 11:31:53 UTC | #1

python
Hi there!

Sorry, for dumb question (i'm new to Python) could you tell me please how i may separate widgets (buttons, inputboxes) from multiple tabs? The following code generated with QTDesigner. The main issue is that "inputbox" and "pushbutton" appears on both tabs. Suppose I need display them only on tab1. Could you direct me please?

Thanks in advance! :slightly_smiling_face:


-- coding: utf-8 --

Form implementation generated from reading ui file 'a.ui'

Created by: PyQt5 UI code generator 5.12.1

WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets import sys

class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(611, 267) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.tabWidget = QtWidgets.QTabWidget(self.centralwidget) self.tabWidget.setGeometry(QtCore.QRect(0, 0, 131, 31)) self.tabWidget.setObjectName("tabWidget") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.tabWidget.addTab(self.tab, "")

python
    self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
    self.lineEdit.setGeometry(QtCore.QRect(190, 80, 251, 41))
    self.lineEdit.setObjectName("lineEdit")
    self.pushButton = QtWidgets.QPushButton(self.centralwidget)
    self.pushButton.setGeometry(QtCore.QRect(270, 170, 89, 25))
    self.pushButton.setObjectName("pushButton")



    MainWindow.setCentralWidget(self.centralwidget)
    self.statusbar = QtWidgets.QStatusBar(MainWindow)
    self.statusbar.setObjectName("statusbar")
    MainWindow.setStatusBar(self.statusbar)


    self.tab_2 = QtWidgets.QWidget()
    self.tab_2.setObjectName("tab_2")
    self.tabWidget.addTab(self.tab_2, "")

    self.retranslateUi(MainWindow)
    self.tabWidget.setCurrentIndex(0)
    QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Tab 1"))
    self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Tab 2"))
    self.pushButton.setText(_translate("MainWindow", "Oxu"))
######### STARTER

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def init(self, *args, obj=None, kwargs): super().init(*args, kwargs) self.setupUi(self)

app = QtWidgets.QApplication(sys.argv)

window = MainWindow() window.show() app.exec()



Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

Issue with tabs was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.