Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:09:31+00:00 2026-06-04T23:09:31+00:00

I’m trying to carry a change from a global variable over to another module

  • 0

I’m trying to carry a change from a global variable over to another module in Python2.7.
I’ve done this in similar situations before but for some reason it won’t work in this instance.
The first file is the one that runs the program. It sets up a global variable and changes it according to the option selected. I’ve pasted a bit of the code below.
runnerMod:

import Tkinter
from main_mod import*

choice = "0"

def main():
    main_mod=functOne()

class GUI(Tkinter.Tk):
    def __init__(self, parent):
        Tkinter.Tk.__init__(self, parent)
        self.parent = parent
            self.initialize()

    def initialize(self):
        self.grid()
        self.update()
        btnOption1 = Tkinter.Button(self, text=u"Option 1", command=self.onButtonClick)
        btnOption1.grid(column=0, row=1)

    def onButtonClick(self):
        selection = "1"
        self.destroy()
        exec 'choice=%s' %selection in globals()
        main()

class menuSelection:
    def OPTIONCHOSEN(self):
        return choice

if __name == "__main__":
    app = GUI(None)
    app.mainloop

I want the global variable named choice from runnerMod.py to carry over to this module.
main_mod:

from runnerMod import menuSelection

def functOne():
    userInput = menuSelection().OPTIONCHOSEN()
    print userInput

The global variable choice starts at 0, but I want to change it to 1 in the runnerMod.py module and have this reflected in the main_mod.py module. Since I’m rewriting an interface to an existing program my options are a little limited in the way its coded. Anyone have any ideas here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:09:32+00:00Added an answer on June 4, 2026 at 11:09 pm

    As it turns out, I couldn’t pass over changes to a global variable from runnerMod.py because it was the module that launched the program. What I had to do was use runnerMod.py to launch the program and then call a function in main_mod.py. This function called BACK to a class in runnerMod.py and loaded up the GUI. Only by calling back and THEN modifying the global variable could I pass over the changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.