Python Forum
[Tkinter] HOW TO: Use Globals In Module ???
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] HOW TO: Use Globals In Module ???
#2
Without passing as a parameter... i would say to create your Groot within setup directly and pass that back to the main program then. Often you will have a settings file with static data that you import to many modules. You should be cautious to use globals so often.

setup.py
# MODULE "setup.py" in moduletest
import tkinter as tk

Groot = tk.Tk()
 
def setup():
    # Create and load the display label into the window
    prompt = '        Press any key        '
    Glabel1 = tk.Label(Groot, text=prompt, width=len(prompt), bg='yellow')
    Glabel1.pack()
    return Groot
main program
import setup #<- imports go at top
...
#Groot = tk.Tk()  # Create the GLOBAL root window
Glabel1 = []     # Global Label identifier
GCOUNT = 0       # Global Keystroke counter
 

# Create and load the display label
Groot = setup.setup()
...
Recommended Tutorials:
Reply


Messages In This Thread
HOW TO: Use Globals In Module ??? - by Webtest - May-09-2019, 12:45 PM
RE: HOW TO: Use Globals In Module ??? - by metulburr - May-09-2019, 05:45 PM
RE: HOW TO: Use Globals In Module ??? - by Webtest - May-10-2019, 04:28 AM
RE: HOW TO: Use Globals In Module ??? - by snippsat - May-10-2019, 06:30 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020