Still progressing in my usage of Page, I create a separate test.py just to test the usage of create_Toplevel1 to create Toplevel1 instead of making the Python GUI the main.I t work great except that I get an additional windows. Looking at the code I can see that there is a difference between create_Toplevel1 and vp_start_gui: vp_start_gui is creating Toplevel1 from root while create_Toplevel1 add an extra-step with w = tk.Toplevel (root) and creating Toplevel1 from w. From what I understand (from tkinter docs) tk.Toplevel is returning "A widget container placed in a new top level window" and so the behaviour I get is normal. I changed create_Toplevel1 to be similar to vp_start_gui and everything is working now how I wanted.
So my questions are "why do we need this w = tk.Toplevel (root)" and obviously "What di I miss to get the expected behaviour" ?
Last edit: Eric Mathieu 2020-06-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I re-read the documentation and I believe I incorrectlyunderstood it at first. vp_start_gui() can be used in another module when the intent is that the GUI is the main one.
I guess my answer is: use vp_start_gui()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, the two functions while being similar are in fact, very different.
If you look in your GUI.py file (your projectfile.py not the projectfile_support.py file) that's where the two are located.
The first function starts off this way...
defvp_start_gui():'''Starting point when module is the main routine.'''
Notice, please the comment. Now, please look at the main starting point for the program...
if__name__=='__main__':
vp_start_gui()
Python calls this function at the very start. This is the entry point of the program. Going back to the vp_start_gui function, you'll see that the init function from the projectfile_support.py file is then called.
So this is the way that a "normal" single form Page project starts up.
However, let's assume that you have a project that needs two different forms (or more) to do the various tasks. That's where the other function comes in.
Take, for example, a cookbook program. You would have a main form, which contains a treeview widget to hold all of the recipe names in the cookbook database, an area that holds a simplified version of the selected recipe and a button toolbar that will allow you to call a form for the recipe file editor, a form that allows you to enter a new recipe from scratch, a form that allows you to scrape various recipe web sites, and maybe some other forms. Each of these forms (windows if you will) are each different Page projects that can be stand alone or called from the button clicks.
If you look at the function createToplevel1 function (or in this case the create_formCookbookMain() function), the first three lines are...
defcreate_formCookbookMain(rt,*args,**kwargs):'''Starting point when module is imported by another module. Correct form of call: 'create_formCookbookMain(root,*args,**kwargs)' .'''
Now to make this work, we'll take a look at the callback for the webscraper button on the toolbar...
Of course, we've imported the project for the webscraper program with...
importScraperGUI1_supportimportScraperGUI1
In the callback function, the call to "ScraperGUI1.createScraper()" brings up the webscraper project. The next line in code (hide_me()) hides the main form while the webscraper form is up, so there is no confusion and chance that anything will be clicked. Once the webscraper project file is done, that is then hidden and the main calling form is restored.
I hope this helps out. I know the response was extremely verbose. Your Page distribution has a simple example under /page/examples/two.
Greg
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Greg for this detailed explanation. As I said I misinterpreted the comments associated to the 2 functions: my undestanding of 'Starting point when module is the main routine.' was when the Python GUI is the main routine. But in fact it is more "when this GUI is the main one". I also read the "Applications with Multiple Top-Level Windows" chapter (which I did not before since I am bultind a single Top-level app).
Again, thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Still progressing in my usage of Page, I create a separate test.py just to test the usage of create_Toplevel1 to create Toplevel1 instead of making the Python GUI the main.I t work great except that I get an additional windows. Looking at the code I can see that there is a difference between create_Toplevel1 and vp_start_gui: vp_start_gui is creating Toplevel1 from root while create_Toplevel1 add an extra-step with w = tk.Toplevel (root) and creating Toplevel1 from w. From what I understand (from tkinter docs) tk.Toplevel is returning "A widget container placed in a new top level window" and so the behaviour I get is normal. I changed create_Toplevel1 to be similar to vp_start_gui and everything is working now how I wanted.
So my questions are "why do we need this w = tk.Toplevel (root)" and obviously "What di I miss to get the expected behaviour" ?
Last edit: Eric Mathieu 2020-06-14
I re-read the documentation and I believe I incorrectlyunderstood it at first. vp_start_gui() can be used in another module when the intent is that the GUI is the main one.
I guess my answer is: use vp_start_gui()
Well, the two functions while being similar are in fact, very different.
If you look in your GUI.py file (your projectfile.py not the projectfile_support.py file) that's where the two are located.
The first function starts off this way...
Notice, please the comment. Now, please look at the main starting point for the program...
Python calls this function at the very start. This is the entry point of the program. Going back to the vp_start_gui function, you'll see that the init function from the projectfile_support.py file is then called.
So this is the way that a "normal" single form Page project starts up.
However, let's assume that you have a project that needs two different forms (or more) to do the various tasks. That's where the other function comes in.
Take, for example, a cookbook program. You would have a main form, which contains a treeview widget to hold all of the recipe names in the cookbook database, an area that holds a simplified version of the selected recipe and a button toolbar that will allow you to call a form for the recipe file editor, a form that allows you to enter a new recipe from scratch, a form that allows you to scrape various recipe web sites, and maybe some other forms. Each of these forms (windows if you will) are each different Page projects that can be stand alone or called from the button clicks.
If you look at the function createToplevel1 function (or in this case the create_formCookbookMain() function), the first three lines are...
Now to make this work, we'll take a look at the callback for the webscraper button on the toolbar...
Of course, we've imported the project for the webscraper program with...
In the callback function, the call to "ScraperGUI1.createScraper()" brings up the webscraper project. The next line in code (hide_me()) hides the main form while the webscraper form is up, so there is no confusion and chance that anything will be clicked. Once the webscraper project file is done, that is then hidden and the main calling form is restored.
I hope this helps out. I know the response was extremely verbose. Your Page distribution has a simple example under /page/examples/two.
Greg
Thank you Greg for this detailed explanation. As I said I misinterpreted the comments associated to the 2 functions: my undestanding of 'Starting point when module is the main routine.' was when the Python GUI is the main routine. But in fact it is more "when this GUI is the main one". I also read the "Applications with Multiple Top-Level Windows" chapter (which I did not before since I am bultind a single Top-level app).
Again, thank you
Any time!