0
import sys
from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtGui  import *
from PyQt4.QtCore import *
import time
import datetime
import re
import random
import csv
from CropClass import *
from Wheat_class import *
from Potato_class import *

win1 = uic.loadUiType("MenuScreen.ui")[0]
win2 = uic.loadUiType("WheatScreen.ui")[0]
win3 = uic.loadUiType("PotatoScreen.ui") [0]
class MenuScreen(QtGui.QMainWindow, win1):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)            
        self.setupUi(self)
        self.BtnCreateSimulation.clicked.connect(self.changeSimulation)
    def changeSimulation(self):

        if self.RdoWheat.isChecked() ==True:
            print("Wheat is picked")
            new_crop=Wheat()   
            self.wheatSimulation()
        elif self.RdoPotato.isChecked() == True:
            print("Potato is picked")
            new_crop = Potato()
            self.PotatoSimulation()
    def wheatSimulation(self):
        print("Hello")
        self.hide()
        WheatWindow.show()
    def PotatoSimulation(self):
        self.hide()
        PotatoWindow.show()

class PotatoScreen(QtGui.QMainWindow, win3):
     def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)            
        self.setupUi(self)

        self.BtnBacktoMenu.clicked.connect(self.BackToMain)
     def BackToMain(self):
        self.hide()
        MenuWindow.show()
class WheatScreen(QtGui.QMainWindow, win2):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)            
        self.setupUi(self)
        new_crop = Wheat()
        self.BtnBacktoMenu.clicked.connect(self.BackToMain)
        self.BtnManual.clicked.connect(self.ManualCalculate)

    def BackToMain(self):
        self.hide()
        MenuWindow.show()
    def ManualCalculate(self):
        water = self.spBoxWater.value()
        light= self.spBoxLight.value()
        print("water", water, "light", light) 



def main():
    app = QtGui.QApplication(sys.argv)
    WheatWindow = WheatScreen(None)
    PotatoWindow = PotatoScreen(None)
    MenuWindow = MenuScreen(None)   
    MenuWindow.show()
    app.exec_()

if __name__ == "__main__":
    main()            

I have created a program in Python which simulates the growth rates of crops. The user is able to chose between the crop is wheat or potatoes I am trying to create a GUI using PYQT. The problem I am having is that when I try and load the program the program is not recognizing the other screen layouts. The main function should be setting up the screen layouts

  • "the program is not recognizing the other screen layouts" I don't understand what that means and what the problem is. Could you create a minimal example showing the error and describe what are the other layouts and how to recognize them? – NoDataDumpNoContribution Aug 30 '17 at 07:40
  • The comment is coming back NameError: global name 'WheatWindow' is not defined so the program is not connecting to the different screen when I use the if __name__ == main: call – da axe man Aug 30 '17 at 08:36
  • Please see: https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them That should help you with WheatWindow although global variables might not be a good style. – NoDataDumpNoContribution Aug 30 '17 at 09:15
  • WheatWindow is the name of the screen I am trying to set up in PYQT, the program will connect all of the screens without the if__name__ ==_"main"__ should I run the main function independently – da axe man Aug 30 '17 at 11:33
  • Thank you for the tip on global variables I used a global counter and saved it – da axe man Aug 30 '17 at 17:53

0 Answers0