user2002495
user2002495

Reputation: 2146

Python: Tkinter access variable from another module

Somewhere in my code I import this module:

import sModule as s

And initialize my main Tkinter window like this:

base = tk.Tk()

mw = MainWindow(base).grid()
s.parent = sys.modules[__name__]

base.mainloop()

And MainWindow class is something like this:

class MainWindow(tk.Frame): 
  def __init__(self, parent):
    self.info1 = tk.StringVar()
    self.info2 = tk.StringVar()

What I'm trying to do is accessing info1 and info2 in sModule like this:

parent.mw.info1.set(str1)

And I'm getting this error:

AttributeError: 'NoneType' object has no attribute 'info1'

Which part is wrong?

Upvotes: 0

Views: 374

Answers (1)

falsetru
falsetru

Reputation: 369064

Replace following line:

mw = MainWindow(base).grid()

with:

mw = MainWindow(base)
mv.grid()

Why? grid() does not return anything; implicitly return None.

Upvotes: 3

Related Questions