I have a requirement where i need to show relevant values in second QComboBox. Ex : If i select South from first QComboBox i.e. Region, second QComboBox i.e. cities should display only cities which are part of South. I went through lot of examples on google or youtube, in all the places they are giving data manually. But my data comes from Tableau Server(Projects, Reports) , so it should not be manual. In this example i created a dummy csv file(Original source is Tableau Server) to try. I am using QT designer to create UI file. names of comboboxes are region and cities Please find code. Sample data looks like this Region,Cities South,Hyderabad South,Bangalore North,Delhi North,Varanasi North,Simla
This is the error message i see when i run code
Traceback (most recent call last):
File "C:\combo.py", line 31, in <module>
welcome = onescreen()
File "C:\combo.py", line 21, in __init__
self.relaventcities(self.region.currentText())
TypeError: relaventcities() takes 1 positional argument but 2 were given
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QDialog,
QStackedWidget
import pandas as pd
data = pd.read_csv("C:/Users/Pavan P/Desktop/comborelevent.csv")
print(data)
region = data['Region']
cities = data['Cities']
#print(region)
#print(cities)
class onescreen(QDialog):
def __init__(self):
super(onescreen,self).__init__()
loadUi("relevent.ui", self)
def regiondata(self):
self.region.addItems(region)
def citiesdata(self):
self.cities.addItems(cities)
def sample(self):
#self.region.addItems(region)
# self.cities.addItems(cities)
self.region.currentTextChanged.connect(self.relaventcities)
# self.relaventcities(self.region.currentText())
self.region.addItems(self.regiondata)
def relaventcities(self, text):
self.cities.clear()
rps = self.citiesdata(text)
if isinstance(rps, list):
self.cities.addItems(rps)
else:
self.cities.addItems(rps)
app = QApplication(sys.argv)
welcome = onescreen()
widget = QStackedWidget()
widget.addWidget(welcome)
widget.setFixedHeight(500)
widget.setFixedWidth(800)
widget.show()
try:
sys.exit(app.exec_())
except Exception as e:
print(e)