Python Forum
Where locate code to load combobox
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where locate code to load combobox
#1
I am a beginner and would like to know where and how to code the loading of two comboboxes.  The GUI was created in QT designer.  First, I have the code to show the form:
import sys
from PyQt5.QtWidgets import QApplication
from mainwindow import UIMainWindow

app = QApplication(sys.argv)
window = UIMainWindow()

window.show()
sys.exit(app.exec_())
I also have this code for my mainwindow
from PyQt5.QtWidgets import QMainWindow
from ui_summary import Ui_MainWindow


class UIMainWindow(QMainWindow):
   def __init__self):
       super(UIMainWindow, self).__init__()
       self.ui = Ui_MainWindow()
       self.ui.setupUi(self)
So, here is the code I have to load two comboboxes (MS and State).  I need to know if it is correct and where to put it.
self.MS.additem(MStatusBox)
       self.State.additem(StateComboBox)

MStatusBox = ['M', 'S']
StateComboBox = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL',
                 'IN', 'IA', 'KN', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV',
                 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT',
                 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
Thanks -- again I am a beginner, please be patient with me
Reply
#2
You can't add items before you define them. As to where that should go, probably in the __init__, right?
But you never define what a self.MS is, or what a self.State is, so... you should probably do that :p Unless that's what's in Ui_MainWindow, I guess, but then it'd be self.ui.MS.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] How can I sync Combobox index to other combobox index? nickzsche 2 2,335 Jan-03-2022, 12:29 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020