Basic GUI Weight converter - python

I am writing a Weight converter to convert killogram to Pounds and vice versa....
Using QT Desginer I have done the interface etc, but now I am stuck trying to figure out how to link the buttons so that when you press one it converts to pound what is entered and vice versa...
Coding so Far:
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(486, 406)
self.pushButton = QtWidgets.QPushButton(MainWindow)
self.pushButton.setGeometry(QtCore.QRect(160, 320, 151, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(MainWindow)
self.pushButton_2.setGeometry(QtCore.QRect(160, 60, 151, 41))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(MainWindow)
self.label.setGeometry(QtCore.QRect(86, 20, 301, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(MainWindow)
self.label_2.setGeometry(QtCore.QRect(20, 230, 131, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(MainWindow)
self.label_3.setGeometry(QtCore.QRect(350, 230, 111, 21))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(MainWindow)
self.lineEdit.setGeometry(QtCore.QRect(20, 170, 113, 41))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(MainWindow)
self.lineEdit_2.setGeometry(QtCore.QRect(340, 170, 113, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_4 = QtWidgets.QLabel(MainWindow)
self.label_4.setGeometry(QtCore.QRect(10, 60, 441, 311))
self.label_4.setToolTipDuration(2)
self.label_4.setText("leh")
self.label_4.setPixmap(QtGui.QPixmap("../../../../../Desktop/unbalanced-
scale.png"))
self.label_4.setIndent(-4)
self.label_4.setObjectName("label_4")
self.label_4.raise_()
self.pushButton.raise_()
self.pushButton_2.raise_()
self.label.raise_()
self.label_2.raise_()
self.label_3.raise_()
self.lineEdit.raise_()
self.lineEdit_2.raise_()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
self.pushButton.setText(_translate("MainWindow", "<<< Pounds to Killogram"))
self.pushButton_2.setText(_translate("MainWindow", "Killogram to Pounds >>>"))
self.label.setText(_translate("MainWindow", " Welcom to PJ Nothnagel\'s Weight Converter!"))
self.label_2.setText(_translate("MainWindow", " Killograms"))
self.label_3.setText(_translate("MainWindow", " Pounds"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QDialog()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Related

pyqt app crashing when function is executed

i wanted to make an rpc changer with pypresence and pyqt and its working, but it crashes whenever i run function that updates the presence - no errors, no exit codes it says that app doesnt respond.
i tried to use qt threading but it didnt work i also tried making it just a normal function, not a loop and it didnt work either.
any ideas?
and heres the code:
from pypresence import Presence
import time
from PyQt5 import QtCore, QtGui, QtWidgets
start = int(time.time())
client_id = "997609359427260416"
RPC = Presence(client_id)
RPC.connect()
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(485, 425)
MainWindow.setStyleSheet("background-color: #1f1f1f;""font: 75 8pt \"Arial\";")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.onclick())
self.pushButton.setGeometry(QtCore.QRect(160, 350, 161, 51))
self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton.setAutoFillBackground(False)
self.pushButton.setStyleSheet("background-color: #a30b00;""color: white;""transition: 0.25s;""font: 12pt;""border-radius: 8px;""")
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(120, 10, 251, 31))
self.label.setStyleSheet("color: white;""font: 18pt")
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(210, 40, 91, 16))
self.label_2.setStyleSheet("color: #a30b00;""font: 12pt")
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(80, 100, 321, 31))
self.lineEdit.setStyleSheet("background-color: rgb(44, 44, 44);""border: 2px solid rgb(60, 60, 60);""border-radius: 5px;""color: white;")
self.lineEdit.setObjectName("lineEdit")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(80, 80, 121, 16))
self.label_3.setStyleSheet("color: white;""font-size: 12pt")
self.label_3.setObjectName("label_3")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(80, 170, 321, 31))
self.lineEdit_2.setStyleSheet("background-color: rgb(44, 44, 44);""border: 2px solid rgb(60, 60, 60);""border-radius: 5px;""color: white;")
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(80, 150, 121, 16))
self.label_4.setStyleSheet("color: white;""font-size: 12pt")
self.label_4.setObjectName("label_4")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(80, 230, 321, 31))
self.lineEdit_3.setStyleSheet("background-color: rgb(44, 44, 44);""border: 2px solid rgb(60, 60, 60);""border-radius: 5px;""color: white;")
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(80, 210, 121, 16))
self.label_5.setStyleSheet("color: white;""font-size: 12pt")
self.label_5.setObjectName("label_5")
self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(80, 290, 321, 31))
self.lineEdit_4.setStyleSheet("background-color: rgb(44, 44, 44);""border: 2px solid rgb(60, 60, 60);""border-radius: 5px;""color: white;")
self.lineEdit_4.setObjectName("lineEdit_4")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(80, 270, 121, 16))
self.label_6.setStyleSheet("color: white;""font-size: 12pt")
self.label_6.setObjectName("label_6")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def onclick(self):
value1 = self.lineEdit.text()
while True:
RPC.update(
large_image = "large", #name of your asset
large_text = "test",
details = value1,
state = "Presence Changer",
start = start,
buttons = [{"label": "kndxiu on TikTok", "url": "https://tiktok.com/#kndxiu"}, {"label": "Website", "url": "https://kndxiu.xyz"}] #up to 2 buttons
)
time.sleep(100)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "SAVE"))
self.label.setText(_translate("MainWindow", "Discord RP Changer"))
self.label_2.setText(_translate("MainWindow", "by kndxiu."))
self.label_3.setText(_translate("MainWindow", "test"))
self.label_4.setText(_translate("MainWindow", "test"))
self.label_5.setText(_translate("MainWindow", "test"))
self.label_6.setText(_translate("MainWindow", "test"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
i found a solution, i used qtimer and replaced onclick function with this:
def onclick(self):
value1 = self.lineEdit.text()
def updateLoop():
RPC.update(
large_image = "large", #name of your asset
large_text = "test",
details = value1,
state = "Presence Changer",
start = start,
buttons = [{"label": "kndxiu on TikTok", "url": "https://tiktok.com/#kndxiu"}, {"label": "Website", "url": "https://kndxiu.xyz"}] #up to 2 buttons
)
self.timer = QTimer()
self.timer.timeout.connect(updateLoop)
self.timer.setInterval(100)
self.timer.start()
and ofc from PyQt5.QtCore import QTimer at the top and it works fine, without freezing

Stackwidget in Pyqt5 python

I'm creating a screen with StackWidget consist of 3 pages.
The problem is that only one page of the stackwidget pages showing all widgets inside it but the other pages cutting three element in the corners, see the photos
the error page:
correct page and i want the other pages show all widgets in the four corners :
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1200, 679)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(30, 100, 93, 28))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(30, 220, 93, 28))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(30, 330, 93, 28))
self.pushButton_3.setObjectName("pushButton_3")
self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
self.stackedWidget.setGeometry(QtCore.QRect(170, 0, 1011, 631))
self.stackedWidget.setObjectName("stackedWidget")
self.page_3 = QtWidgets.QWidget()
self.page_3.setObjectName("page_3")
self.pushButton_4 = QtWidgets.QPushButton(self.page_3)
self.pushButton_4.setGeometry(QtCore.QRect(10, 10, 93, 28))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(self.page_3)
self.pushButton_5.setGeometry(QtCore.QRect(880, 20, 93, 28))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(self.page_3)
self.pushButton_6.setGeometry(QtCore.QRect(10, 580, 93, 28))
self.pushButton_6.setObjectName("pushButton_6")
self.pushButton_7 = QtWidgets.QPushButton(self.page_3)
self.pushButton_7.setGeometry(QtCore.QRect(890, 590, 93, 28))
self.pushButton_7.setObjectName("pushButton_7")
self.stackedWidget.addWidget(self.page_3)
self.page_4 = QtWidgets.QWidget()
self.page_4.setObjectName("page_4")
self.lineEdit = QtWidgets.QLineEdit(self.page_4)
self.lineEdit.setGeometry(QtCore.QRect(10, 30, 113, 22))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.page_4)
self.lineEdit_2.setGeometry(QtCore.QRect(870, 580, 113, 22))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.page_4)
self.lineEdit_3.setGeometry(QtCore.QRect(30, 570, 113, 22))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.page_4)
self.lineEdit_4.setGeometry(QtCore.QRect(860, 30, 113, 22))
self.lineEdit_4.setObjectName("lineEdit_4")
self.stackedWidget.addWidget(self.page_4)
self.page_5 = QtWidgets.QWidget()
self.page_5.setObjectName("page_5")
self.calendarWidget = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget.setGeometry(QtCore.QRect(10, 10, 392, 236))
self.calendarWidget.setObjectName("calendarWidget")
self.calendarWidget_2 = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget_2.setGeometry(QtCore.QRect(600, 20, 392, 236))
self.calendarWidget_2.setObjectName("calendarWidget_2")
self.calendarWidget_3 = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget_3.setGeometry(QtCore.QRect(610, 380, 392, 236))
self.calendarWidget_3.setObjectName("calendarWidget_3")
self.calendarWidget_4 = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget_4.setGeometry(QtCore.QRect(10, 380, 392, 236))
self.calendarWidget_4.setObjectName("calendarWidget_4")
self.stackedWidget.addWidget(self.page_5)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1200, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "1"))
self.pushButton_2.setText(_translate("MainWindow", "2"))
self.pushButton_3.setText(_translate("MainWindow", "3"))
self.pushButton_4.setText(_translate("MainWindow", "PushButton"))
self.pushButton_5.setText(_translate("MainWindow", "PushButton"))
self.pushButton_6.setText(_translate("MainWindow", "PushButton"))
self.pushButton_7.setText(_translate("MainWindow", "PushButton"))
Blockquote
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction ,QFileDialog
from stackwidgettest import *
class MyForm(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.moveforward)
self.ui.pushButton_2.clicked.connect(self.moveback)
self.ui.pushButton_3.clicked.connect(self.movebacks)
def moveforward(self):
self.ui.page_3.show()
self.ui.page_4.hide()
self.ui.page_5.hide()
def moveback(self):
self.ui.page_3.hide()
self.ui.page_4.show()
self.ui.page_5.hide()
def movebacks(self):
self.ui.page_3.hide()
self.ui.page_4.hide()
self.ui.page_5.show()
if __name__=="__main__":
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())
The problem solved by setCurrentIndex() method for the stackwidget

issue with QScrollArea

I am trying to add some check boxes in scroll area.but for me it is not working properly.i am new in python could anyone help?
import PyQt5
from PyQt5 import QtCore, QtGui, QtWidgets
from configparser import ConfigParser
import paramiko
import threading
import os
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
class Ui_MainWindow(object):
def __init__(self, parent=None):
self.configur = ConfigParser()
self.configur.read('ServerConfigurationDetails.ini')
self.serverName=self.configur.sections()
print(self.serverName)
self.getComponents = self.configur.options("Component")
self.sLen = len(self.serverName)
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(951, 634)
font = QtGui.QFont()
font.setPointSize(10)
MainWindow.setFont(font)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(150, 220, 91, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(250, 220, 231, 31))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(700, 40, 101, 31))
self.pushButton.setObjectName("pushButton")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(140, 260, 681, 81))
self.groupBox.setObjectName("groupBox")
self.radioButton = QtWidgets.QRadioButton(self.groupBox)
self.radioButton.setGeometry(QtCore.QRect(10, 30, 201, 20))
self.radioButton.setObjectName("radioButton")
self.radioButton_2 = QtWidgets.QRadioButton(self.groupBox)
self.radioButton_2.setGeometry(QtCore.QRect(220, 30, 201, 20))
self.radioButton_2.setObjectName("radioButton_2")
self.checkBox = QtWidgets.QCheckBox(self.groupBox)
self.checkBox.setEnabled(False)
self.checkBox.setGeometry(QtCore.QRect(10, 50, 231, 31))
self.checkBox.setChecked(True)
self.checkBox.setObjectName("checkBox")
self.radioButton_3 = QtWidgets.QRadioButton(self.groupBox)
self.radioButton_3.setGeometry(QtCore.QRect(420, 30, 171, 20))
self.radioButton_3.setObjectName("radioButton_3")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(280, 40, 411, 31))
self.lineEdit.setObjectName("lineEdit")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(130, 40, 131, 31))
self.label_3.setObjectName("label_3")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(140, 125, 661, 21))
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(130, 110, 681, 101))
self.scrollArea.setAccessibleDescription("")
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 679, 99))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
c=10
n=0
x = 10
y = 10
print(self.sLen)
for i in range(self.sLen):
if(n==4):
n=0
x=10
y=y+20
self.checkbox1 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
self.checkbox1.setGeometry(QtCore.QRect(x+1, y+1, 161, 20))
self.checkbox1.setText(self.serverName[i])
self.checkbox1.setObjectName(self.serverName[i])
print(x)
print(n)
n=n+1
if(n==4):
x=10
y = y+20
else:
x= x+180
## self.checkBox_2 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_2.setGeometry(QtCore.QRect(10, 10, 161, 20))
## self.checkBox_2.setObjectName("checkBox_2")
## self.checkBox_3 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_3.setGeometry(QtCore.QRect(180, 10, 131, 20))
## self.checkBox_3.setObjectName("checkBox_3")
## self.checkBox_4 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_4.setGeometry(QtCore.QRect(350, 10, 151, 20))
## self.checkBox_4.setObjectName("checkBox_4")
## self.checkBox_5 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_5.setGeometry(QtCore.QRect(530, 10, 141, 20))
## self.checkBox_5.setObjectName("checkBox_5")
## self.checkBox_6 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_6.setGeometry(QtCore.QRect(10, 30, 161, 20))
## self.checkBox_6.setObjectName("checkBox_6")
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.scrollArea_2 = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea_2.setGeometry(QtCore.QRect(140, 380, 681, 191))
self.scrollArea_2.setWidgetResizable(True)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 679, 189))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_2)
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(70, 340, 811, 20))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 951, 26))
self.menubar.setObjectName("menubar")
self.menuhelp = QtWidgets.QMenu(self.menubar)
self.menuhelp.setObjectName("menuhelp")
MainWindow.setMenuBar(self.menubar)
self.actionAbout = QtWidgets.QAction(MainWindow)
self.actionAbout.setObjectName("actionAbout")
self.menuhelp.addAction(self.actionAbout)
self.menubar.addAction(self.menuhelp.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:10pt;\">Component</span></p></body></html>"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "eComm"))
self.comboBox_2.setItemText(1, _translate("MainWindow", "workproc"))
self.pushButton.setText(_translate("MainWindow", "Search"))
self.groupBox.setTitle(_translate("MainWindow", "Other Details"))
self.radioButton.setText(_translate("MainWindow", "Only Search in Archive"))
self.radioButton_2.setText(_translate("MainWindow", "Also Search in Archive"))
self.checkBox.setText(_translate("MainWindow", "Auto Download"))
self.radioButton_3.setText(_translate("MainWindow", "Only Search in Log"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p>Search String<span style=\" color:#ff0000;\">*</span></p></body></html>"))
## self.checkBox_2.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_3.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_4.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_5.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_6.setText(_translate("MainWindow", "CheckBox"))
self.menuhelp.setTitle(_translate("MainWindow", "Help"))
self.actionAbout.setText(_translate("MainWindow", "About"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
as you can see the scroll area is not showing properly.i have some 20 servers to show.this server list is coming from ini file and i need to show the check boxes in that scroll area.
you need to use QLayout to arrange you widgets. check out
Qt Designer -> "Widget Box" docker -> "Layouts" section
For the scrollarea part:
create scrollarea scroll_area = QScrollArea()
create view widget you want to put inside scrollarea base_widget = QWidget()
install view layout for view widget base_layout = QVBoxLayout(base_widget)
install view widget into scrollarea scroll_area.setWidget(base_widget)
fill in objects with view layout base_layout.addWidget(QLabel('foo')) base_layout.addWidget(QPushButton('bar')) base_layout.addLayout(my_sub_layout) etc.

How to link my Kuthi.py file with my .xml file after clicking submit?

i have a python file which is designed using pyqt5 designer, i have .xml file which is the expected output, in this .xml file, there is spaces which will be replaced according to the desired input values?
like this, address will be in address location.
Here is my kuthi.py code:
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(190, 330, 75, 23))
self.pushButton.setObjectName("pushButton")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(200, 190, 261, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.dateEdit = QtWidgets.QDateEdit(self.centralwidget)
self.dateEdit.setGeometry(QtCore.QRect(200, 260, 111, 22))
self.dateEdit.setObjectName("dateEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(80, 230, 101, 16))
self.label_4.setObjectName("label_4")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(80, 170, 111, 16))
self.label_2.setObjectName("label_2")
self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(200, 230, 261, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(80, 130, 81, 16))
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(200, 130, 261, 20))
self.lineEdit.setObjectName("lineEdit")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(80, 260, 111, 16))
self.label_5.setObjectName("label_5")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(80, 200, 111, 16))
self.label_3.setObjectName("label_3")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(200, 160, 261, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Submit"))
self.label_4.setText(_translate("MainWindow", "Enter Address :"))
self.label_2.setText(_translate("MainWindow", "Enter Father\'s Name :"))
self.label.setText(_translate("MainWindow", "Enter Full Name :"))
self.label_5.setText(_translate("MainWindow", "Enter Date of Birth :"))
self.label_3.setText(_translate("MainWindow", "Enter Mother\'s Name :"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Making Push button label change every click on pyqt5

I'm building a gui using pyqt5. I'm trying to figure out how to change a button every click:
in my code I have a push button called Chuck_Release. Basically, I want it to show either "chuck" or "release" under some conditions, but until then I just want it to change it's title every click, with the starting state of "chuck", but I can't seem to figure out how to do it.
This is my code:
import sys, time
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(685, 459)
self.exitbtn = QtWidgets.QPushButton(Dialog)
self.exitbtn.setGeometry(QtCore.QRect(608, 431, 75, 23))
self.exitbtn.setObjectName("exitbtn")
self.Typelist = QtWidgets.QComboBox(Dialog)
self.Typelist.setGeometry(QtCore.QRect(50, 70, 59, 20))
self.Typelist.setObjectName("Typelist")
self.Typelist.addItem("")
self.Typelist.addItem("")
self.Typelist.addItem("")
self.Chuck_Release = QtWidgets.QPushButton(Dialog)
self.Chuck_Release.setGeometry(QtCore.QRect(50, 100, 75, 23))
self.Chuck_Release.setObjectName("Chuck_Release")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(50, 20, 37, 16))
self.label.setObjectName("label")
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(25, 160, 511, 192))
self.textBrowser.setObjectName("textBrowser")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(50, 40, 133, 20))
self.lineEdit.setObjectName("lineEdit")
self.Runbtn = QtWidgets.QPushButton(Dialog)
self.Runbtn.setGeometry(QtCore.QRect(420, 60, 91, 61))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.Runbtn.setFont(font)
self.Runbtn.setObjectName("Runbtn")
self.getSerial = QtWidgets.QPushButton(Dialog)
self.getSerial.setGeometry(QtCore.QRect(200, 40, 75, 23))
self.getSerial.setObjectName("getSerial")
self.exitbtn.clicked.connect(self.exitclicked)
self.Chuck_Release.clicked.connect(self.chuckclicked)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "NEW GUI"))
self.exitbtn.setText(_translate("Dialog", "Exit"))
self.Typelist.setItemText(0, _translate("Dialog", "Type 1"))
self.Typelist.setItemText(1, _translate("Dialog", "Type2"))
self.Typelist.setItemText(2, _translate("Dialog", "Type 3"))
self.Chuck_Release.setText(_translate("Dialog", "Chuck"))
self.label.setText(_translate("Dialog", "Serial #"))
self.Runbtn.setText(_translate("Dialog", "Run"))
self.getSerial.setText(_translate("Dialog", "Enter"))
def exitclicked(self,Dialog):
sys.exit()
def chuckclicked(self,Dialog):
self.Chuck_Release.setText("Release") ***this is my function for chuckrelease push button***
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
I would love if someone could explain me the process of how to get it done.
Thanks! :D
checkable : bool
This property holds whether the button is checkable
By default, the button is not checkable.
checked : bool
This property holds whether the button is checked
Only checkable buttons can be checked. By default, the button is unchecked.
import sys, time
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(685, 459)
self.exitbtn = QtWidgets.QPushButton(Dialog)
self.exitbtn.setGeometry(QtCore.QRect(608, 431, 75, 23))
self.exitbtn.setObjectName("exitbtn")
self.Typelist = QtWidgets.QComboBox(Dialog)
self.Typelist.setGeometry(QtCore.QRect(50, 70, 59, 20))
self.Typelist.setObjectName("Typelist")
self.Typelist.addItem("")
self.Typelist.addItem("")
self.Typelist.addItem("")
self.Chuck_Release = QtWidgets.QPushButton(Dialog)
self.Chuck_Release.setGeometry(QtCore.QRect(50, 100, 75, 23))
self.Chuck_Release.setObjectName("Chuck_Release")
self.Chuck_Release.setCheckable(True) # +++
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(50, 20, 37, 16))
self.label.setObjectName("label")
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(25, 160, 511, 192))
self.textBrowser.setObjectName("textBrowser")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(50, 40, 133, 20))
self.lineEdit.setObjectName("lineEdit")
self.Runbtn = QtWidgets.QPushButton(Dialog)
self.Runbtn.setGeometry(QtCore.QRect(420, 60, 91, 61))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.Runbtn.setFont(font)
self.Runbtn.setObjectName("Runbtn")
self.getSerial = QtWidgets.QPushButton(Dialog)
self.getSerial.setGeometry(QtCore.QRect(200, 40, 75, 23))
self.getSerial.setObjectName("getSerial")
self.exitbtn.clicked.connect(self.exitclicked)
self.Chuck_Release.clicked.connect(self.chuckclicked)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "NEW GUI"))
self.exitbtn.setText(_translate("Dialog", "Exit"))
self.Typelist.setItemText(0, _translate("Dialog", "Type 1"))
self.Typelist.setItemText(1, _translate("Dialog", "Type2"))
self.Typelist.setItemText(2, _translate("Dialog", "Type 3"))
self.Chuck_Release.setText(_translate("Dialog", "Chuck"))
self.label.setText(_translate("Dialog", "Serial #"))
self.Runbtn.setText(_translate("Dialog", "Run"))
self.getSerial.setText(_translate("Dialog", "Enter"))
def exitclicked(self,Dialog):
sys.exit()
def chuckclicked(self,Dialog):
# print(self.Chuck_Release.isChecked())
if self.Chuck_Release.isChecked(): # +++
self.Chuck_Release.setText("Release")
else:
self.Chuck_Release.setText("Chuck")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())

Categories

Resources