How to change value of a variable of a python file from another file? The 2019 Stack Overflow Developer Survey Results Are InHow do I check whether a file exists without exceptions?How do I copy a file in Python?How can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How do I pass a variable by reference?Why can't Python parse this JSON data?How do I list all files of a directory?How to access environment variable values?
Idiomatic way to prevent slicing?
Inflated grade on resume at previous job, might former employer tell new employer?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
How can I create a character who can assume the widest possible range of creature sizes?
Manuscript was "unsubmitted" because the manuscript was deposited in Arxiv Preprints
Is there a name of the flying bionic bird?
What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?
Can distinct morphisms between curves induce the same morphism on singular cohomology?
How to manage monthly salary
Is bread bad for ducks?
Access elements in std::string where positon of string is greater than its size
How long do I have to send payment?
The difference between dialogue marks
How to change the limits of integration
Realistic Alternatives to Dust: What Else Could Feed a Plankton Bloom?
How come people say “Would of”?
Unbreakable Formation vs. Cry of the Carnarium
Should I use my personal or workplace e-mail when registering to external websites for work purpose?
Are USB sockets on wall outlets live all the time, even when the switch is off?
Does light intensity oscillate really fast since it is a wave?
"What time...?" or "At what time...?" - what is more grammatically correct?
I see my dog run
Inline version of a function returns different value then non-inline version
Where does the "burst of radiance" from Holy Weapon originate?
How to change value of a variable of a python file from another file?
The 2019 Stack Overflow Developer Survey Results Are InHow do I check whether a file exists without exceptions?How do I copy a file in Python?How can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?How do I sort a dictionary by value?How do I pass a variable by reference?Why can't Python parse this JSON data?How do I list all files of a directory?How to access environment variable values?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have two python file. I want to change variable value by calling the module.
test.py
import tkinter
from tkinter import *
from tkinter import ttk
class Master(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.initialize()
def initialize(self):
self.grid()
self.my_clock = StringVar(self)
self.my_clock.set("12:05")
clock =Label(self,textvariable = self.my_clock,height=1,
width=5,fg="black",bg="white",font=("Sans", 32,"bold"))
clock.grid(column=0,row=0,sticky='SW')
window = Master(None)
window.configure(background="white")
window.mainloop()
test1.py
import test
test.window.my_clock.set("13:05")
I could not change the value of my_clock variable from test1.py file.How could I change the value of my_clock variable from test1.py file.
python python-2.7 tkinter raspberry-pi3
add a comment |
I have two python file. I want to change variable value by calling the module.
test.py
import tkinter
from tkinter import *
from tkinter import ttk
class Master(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.initialize()
def initialize(self):
self.grid()
self.my_clock = StringVar(self)
self.my_clock.set("12:05")
clock =Label(self,textvariable = self.my_clock,height=1,
width=5,fg="black",bg="white",font=("Sans", 32,"bold"))
clock.grid(column=0,row=0,sticky='SW')
window = Master(None)
window.configure(background="white")
window.mainloop()
test1.py
import test
test.window.my_clock.set("13:05")
I could not change the value of my_clock variable from test1.py file.How could I change the value of my_clock variable from test1.py file.
python python-2.7 tkinter raspberry-pi3
Why do you pass aparent
argument to your class? What do you think you can pass here? ATk
instance does not have a parent.
– fhdrsdg
Mar 8 at 12:47
add a comment |
I have two python file. I want to change variable value by calling the module.
test.py
import tkinter
from tkinter import *
from tkinter import ttk
class Master(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.initialize()
def initialize(self):
self.grid()
self.my_clock = StringVar(self)
self.my_clock.set("12:05")
clock =Label(self,textvariable = self.my_clock,height=1,
width=5,fg="black",bg="white",font=("Sans", 32,"bold"))
clock.grid(column=0,row=0,sticky='SW')
window = Master(None)
window.configure(background="white")
window.mainloop()
test1.py
import test
test.window.my_clock.set("13:05")
I could not change the value of my_clock variable from test1.py file.How could I change the value of my_clock variable from test1.py file.
python python-2.7 tkinter raspberry-pi3
I have two python file. I want to change variable value by calling the module.
test.py
import tkinter
from tkinter import *
from tkinter import ttk
class Master(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.initialize()
def initialize(self):
self.grid()
self.my_clock = StringVar(self)
self.my_clock.set("12:05")
clock =Label(self,textvariable = self.my_clock,height=1,
width=5,fg="black",bg="white",font=("Sans", 32,"bold"))
clock.grid(column=0,row=0,sticky='SW')
window = Master(None)
window.configure(background="white")
window.mainloop()
test1.py
import test
test.window.my_clock.set("13:05")
I could not change the value of my_clock variable from test1.py file.How could I change the value of my_clock variable from test1.py file.
python python-2.7 tkinter raspberry-pi3
python python-2.7 tkinter raspberry-pi3
edited Mar 8 at 9:26
Akash Nil
asked Mar 8 at 8:33
Akash NilAkash Nil
363416
363416
Why do you pass aparent
argument to your class? What do you think you can pass here? ATk
instance does not have a parent.
– fhdrsdg
Mar 8 at 12:47
add a comment |
Why do you pass aparent
argument to your class? What do you think you can pass here? ATk
instance does not have a parent.
– fhdrsdg
Mar 8 at 12:47
Why do you pass a
parent
argument to your class? What do you think you can pass here? A Tk
instance does not have a parent.– fhdrsdg
Mar 8 at 12:47
Why do you pass a
parent
argument to your class? What do you think you can pass here? A Tk
instance does not have a parent.– fhdrsdg
Mar 8 at 12:47
add a comment |
3 Answers
3
active
oldest
votes
If you want your program test1
to show the window, then it needs to call window.mainloop()
.
import test
window = test.Master(None)
window.my_clock.set("13:05")
window.mainloop()
add a comment |
You only call the mainloop when you run test.py
directly (when __name__ == "__main__"
). When you import it you need to run the mainloop again. Change test1.py
to:
import test
m = test.Master(None)
m.my_clock.set("13:05")
m.mainloop()
add a comment |
When you do:
import test
test.Master(None).my_clock.set("13:05")
You do the following:
- Import test
- Instanciate a new instance of the class
Master
(<=> a new object) - Set a new value for the property
my_clock
of your new object - Then this new object "disappear", as it was not stored into a variable.
Two possibilities here:
Instanciate your object in your test.py
test.py
class Master(Tk):
def __init__(self,parent=None):
(...)
window = Master()
(...)
test2.py
import test
test.window.my_clock.set("13:05")
Or use a class variable
test.py
class Master(Tk):
my_clock = StringVar()
def __init__(self,parent=None):
(...)
test2.py
import test
test.Master.my_clock.set("13:05")
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55059393%2fhow-to-change-value-of-a-variable-of-a-python-file-from-another-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want your program test1
to show the window, then it needs to call window.mainloop()
.
import test
window = test.Master(None)
window.my_clock.set("13:05")
window.mainloop()
add a comment |
If you want your program test1
to show the window, then it needs to call window.mainloop()
.
import test
window = test.Master(None)
window.my_clock.set("13:05")
window.mainloop()
add a comment |
If you want your program test1
to show the window, then it needs to call window.mainloop()
.
import test
window = test.Master(None)
window.my_clock.set("13:05")
window.mainloop()
If you want your program test1
to show the window, then it needs to call window.mainloop()
.
import test
window = test.Master(None)
window.my_clock.set("13:05")
window.mainloop()
answered Mar 8 at 8:39
BoarGulesBoarGules
8,79721228
8,79721228
add a comment |
add a comment |
You only call the mainloop when you run test.py
directly (when __name__ == "__main__"
). When you import it you need to run the mainloop again. Change test1.py
to:
import test
m = test.Master(None)
m.my_clock.set("13:05")
m.mainloop()
add a comment |
You only call the mainloop when you run test.py
directly (when __name__ == "__main__"
). When you import it you need to run the mainloop again. Change test1.py
to:
import test
m = test.Master(None)
m.my_clock.set("13:05")
m.mainloop()
add a comment |
You only call the mainloop when you run test.py
directly (when __name__ == "__main__"
). When you import it you need to run the mainloop again. Change test1.py
to:
import test
m = test.Master(None)
m.my_clock.set("13:05")
m.mainloop()
You only call the mainloop when you run test.py
directly (when __name__ == "__main__"
). When you import it you need to run the mainloop again. Change test1.py
to:
import test
m = test.Master(None)
m.my_clock.set("13:05")
m.mainloop()
answered Mar 8 at 8:39
fhdrsdgfhdrsdg
7,38322038
7,38322038
add a comment |
add a comment |
When you do:
import test
test.Master(None).my_clock.set("13:05")
You do the following:
- Import test
- Instanciate a new instance of the class
Master
(<=> a new object) - Set a new value for the property
my_clock
of your new object - Then this new object "disappear", as it was not stored into a variable.
Two possibilities here:
Instanciate your object in your test.py
test.py
class Master(Tk):
def __init__(self,parent=None):
(...)
window = Master()
(...)
test2.py
import test
test.window.my_clock.set("13:05")
Or use a class variable
test.py
class Master(Tk):
my_clock = StringVar()
def __init__(self,parent=None):
(...)
test2.py
import test
test.Master.my_clock.set("13:05")
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
add a comment |
When you do:
import test
test.Master(None).my_clock.set("13:05")
You do the following:
- Import test
- Instanciate a new instance of the class
Master
(<=> a new object) - Set a new value for the property
my_clock
of your new object - Then this new object "disappear", as it was not stored into a variable.
Two possibilities here:
Instanciate your object in your test.py
test.py
class Master(Tk):
def __init__(self,parent=None):
(...)
window = Master()
(...)
test2.py
import test
test.window.my_clock.set("13:05")
Or use a class variable
test.py
class Master(Tk):
my_clock = StringVar()
def __init__(self,parent=None):
(...)
test2.py
import test
test.Master.my_clock.set("13:05")
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
add a comment |
When you do:
import test
test.Master(None).my_clock.set("13:05")
You do the following:
- Import test
- Instanciate a new instance of the class
Master
(<=> a new object) - Set a new value for the property
my_clock
of your new object - Then this new object "disappear", as it was not stored into a variable.
Two possibilities here:
Instanciate your object in your test.py
test.py
class Master(Tk):
def __init__(self,parent=None):
(...)
window = Master()
(...)
test2.py
import test
test.window.my_clock.set("13:05")
Or use a class variable
test.py
class Master(Tk):
my_clock = StringVar()
def __init__(self,parent=None):
(...)
test2.py
import test
test.Master.my_clock.set("13:05")
When you do:
import test
test.Master(None).my_clock.set("13:05")
You do the following:
- Import test
- Instanciate a new instance of the class
Master
(<=> a new object) - Set a new value for the property
my_clock
of your new object - Then this new object "disappear", as it was not stored into a variable.
Two possibilities here:
Instanciate your object in your test.py
test.py
class Master(Tk):
def __init__(self,parent=None):
(...)
window = Master()
(...)
test2.py
import test
test.window.my_clock.set("13:05")
Or use a class variable
test.py
class Master(Tk):
my_clock = StringVar()
def __init__(self,parent=None):
(...)
test2.py
import test
test.Master.my_clock.set("13:05")
edited Mar 8 at 9:02
answered Mar 8 at 8:38
olinox14olinox14
1,260618
1,260618
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
add a comment |
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Method1 shows the window with previous value. value not updated . and second method shows an error 'NoneType' object has no attribute '_root'
– Akash Nil
Mar 8 at 8:53
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
Those are only explanations about why your code could not work, and ideas to solve your problem, not a fully functionnal solution...
– olinox14
Mar 8 at 9:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55059393%2fhow-to-change-value-of-a-variable-of-a-python-file-from-another-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why do you pass a
parent
argument to your class? What do you think you can pass here? ATk
instance does not have a parent.– fhdrsdg
Mar 8 at 12:47