0

I'm creating a GUI and I had an issue. My GUI will work with 3 windows, the first one is going to read the user's ID and see if he have finished the tutorials. If he finished and want to watch any tutorial again, it will open the WINDOW2, if he didn't finish yet it will open the WINDOW3. In my code, I have for example the tutorials of the section 111, which are inside a folder in my system. To acess and list them I did:

path_111 = "D:\\Users\\raulc\\Documents\\AMBIENTES\\videos\\111"
p111 = os.listdir(path_111)

But now on PySimpleGUI I don't know how to make the layout have the number of Buttons equal to the number of tutorials. Since p111 is updated every time a new file is inserted on the folder, the number of buttons should be updated too, without me. Does anyone knows how to that?

Raul Lopes
  • 17
  • 2
  • Variables don't update. OS directories do - https://stackoverflow.com/questions/597903/monitoring-contents-of-files-directories – OneCricketeer May 17 '22 at 13:56
  • But every time a file is uploaded on the folder, p111 (which is a list of the files that are in the "111" folder) is going to increase it's size – Raul Lopes May 17 '22 at 14:19
  • Create a window based on the number of files when starting, or Refresh a window based on the number of files as it changed immediately ? – Jason Yang May 17 '22 at 15:38
  • Create as many buttons as you are likely to need, but hide any that don't have a corresponding file yet. Then unhide them as needed. – BoarGules May 17 '22 at 15:42
  • It's a good strategy, but what should I do if the Button name is associeted to the file name. – Raul Lopes May 17 '22 at 16:06
  • `p111` will not update as files are added unless you repeated run `os.listdir` in some loop. Try it. And when you re-run that, you would need to clear all the existing buttons and reload with all new ones (please [edit] your question to show how you draw buttons now) – OneCricketeer May 17 '22 at 16:17

0 Answers0