Where locate code to load combobox - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Where locate code to load combobox (/thread-2099.html) |
Where locate code to load combobox - birdieman - Feb-19-2017 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 RE: Where locate code to load combobox - nilamo - Feb-20-2017 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. |