D
D
Dmitry Prilepsky2021-08-29 18:02:47
Python
Dmitry Prilepsky, 2021-08-29 18:02:47

How to change windows in PySimleGui depending on what is selected in sg.Combo?

I need to create a GUI for a program that translates mods for a game. The translator has several modes and input variables are also different. I want the interface to change depending on what is selected in sg.Combo. I wrote this code:
(Class with layouts)

list_commands = [COMMANDS.ADDITIONAL_ENGLISH, COMMANDS.ADDITIONAL_RUSSIAN, COMMANDS.TRANSFER_FILE,
                 COMMANDS.ALL_TRANSLATE_DIRECTRY, COMMANDS.TRANSLATE_FILE, COMMANDS.ALL_TRANSFER_DIRECTORY,
                 COMMANDS.STREAMLINE_FILE, COMMANDS.STREAMLINE_DIRECTORY, COMMANDS.SEARCH_UPDATE_STRING_FILE,
                 COMMANDS.SEARCH_UNTRANS_STRING_FILE]

class INTERFACE:
    ADD_FILE_ENG = 

    ADD_FILE_RU = 

Interface change
def change_interfase(self, mode):
        if mode == COMMANDS.ADDITIONAL_ENGLISH:
            window = sg.Window('LTA (localization translator assistant)', INTERFACE.ADD_FILE_ENG)
        elif mode == COMMANDS.ADDITIONAL_RUSSIAN:
            window = sg.Window('LTA (localization translator assistant)', INTERFACE.ADD_FILE_RU)

A function that sets the initial interface
def get_default_interface(self):
        return sg.Window('LTA (localization translator assistant)', INTERFACE.DEFAULT, size=(700, 100))

Just switching windows
interface = work_with_interface.get_default_interface()

while True:
    try:
        event, values = interface.read()
        #print(event, values) #debug
        if event in (None, 'Exit', 'Cancel'):
            break
        elif event =='MODE':
            interface.Close()
            interface = work_with_interface.change_interfase(values['MODE'])

This code works until I select the same option in sg.Combo. Then the code breaks and throws out the following error:
612ba0e108aec537520143.png
Please tell me how to fix this?
PS if you need more code, then the whole project is on the git https://github.com/HartExaVersion2/FileMerger and, in theory, it should run out of the box

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Prilepsky, 2021-09-03
@HartX

The point was that I initialized the ayouts once, but it is necessary for each new switching to the mode in the ComboBox. For this, INTERFACE has been redesigned as follows:

class Interfaces:
    def get_add_file_eng(self):
        return 

    def get_add_file_ru(self):
        return 

And then I just redid their calls .
It was suggested to me on stackoverflow: https://stackoverflow.com/questions/68990845/how-d...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question