Retrieving value from Tkinter Entry box - python

I am trying to get Tkinter to return the value from the input box, but I cannot seem to get it to work.
This is my first attempt trying Tkinter out, s
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\rik\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "n:\regnskab\Afregning\RIK\Udvikling\gui\app2.py", line 43, in step_1
periode_2 = get_period(self)
NameError: name 'get_period' is not defined
import tkinter as tk
from tkinter import ttk
class Mainframe(tk.Tk):
def __init__(self, *args, **kvargs):
super().__init__(*args, **kvargs)
self.title("app")
UserInputFrame(self).grid(row=1, column=0)
ControlsFrame(self).grid(row=2, column=0)
ButtonFrame(self).grid(row=3, column=0)
class UserInputFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
self.user_input_year = tk.StringVar(value="2021")
label_entry_year = ttk.Label(self, text="Year")
self.entry_year = ttk.Entry(self, textvariable=self.user_input_year)
label_entry_year.grid(row=2, column=0, sticky="W", padx=10, pady=5)
self.entry_year.grid(row=2, column=1, sticky="EW")
def get_period(self):
print(self.entry_year.get())
class ControlsFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
step_1_button = ttk.Button(self, text="Step 1", command=self.step_1)
step_1_button.grid(row=10, column=0, sticky="EW")
def step_1(self):
periode_2 = get_period(self)
print("step 1")
class ButtonFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
quit_button = ttk.Button(self, text="Quit", command=quit)
quit_button.grid(row=4, column=1, sticky="EW")
def quit(self):
app.destroy
app = Mainframe()
app.mainloop()

You have to learn OOP :)
get_period() is not standalone function but it is function inside class UserInputFrame and you try to access it in class ControlsFrame. You can't access function for one class in other class this way.
You would have to get instance of UserInputFrame,
user_input_frame = UserInputFrame(self)
user_input_frame.grid(row=1, column=0)
send it as argument to ControlsFrame
ControlsFrame(self, user_input_frame).grid(row=2, column=0)
keep it in class variable
class ControlsFrame(ttk.Frame):
def __init__(self, container, user_input_frame):
super().__init__(container)
self.user_input_frame = user_input_frame
and then you can use it
def step_1(self):
self.user_input_frame.get_period() # without `self` in `get_period()`
OR better method
You should assing UserInputFrame to class variable in Mainframe
self.user_input_frame = UserInputFrame(self)
self.user_input_frame.grid(row=1, column=0)
and then other objects (created in Mainframe) may access Mainframe (which is its paret/master) using self.master and then they can access elements in Mainframe like self.master.userinputframe
periode_2 = self.master.user_input_frame.get_period() # without `self` in `get_period()`
import tkinter as tk
from tkinter import ttk
class Mainframe(tk.Tk):
def __init__(self, *args, **kvargs):
super().__init__(*args, **kvargs)
self.title("app")
self.user_input_frame = UserInputFrame(self)
self.user_input_frame.grid(row=1, column=0)
ControlsFrame(self).grid(row=2, column=0)
ButtonFrame(self).grid(row=3, column=0)
class UserInputFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
self.user_input_year = tk.StringVar(value="2021")
label_entry_year = ttk.Label(self, text="Year")
self.entry_year = ttk.Entry(self, textvariable=self.user_input_year)
label_entry_year.grid(row=2, column=0, sticky="W", padx=10, pady=5)
self.entry_year.grid(row=2, column=1, sticky="EW")
def get_period(self):
#print(self.entry_year.get())
return self.entry_year.get()
class ControlsFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
step_1_button = ttk.Button(self, text="Step 1", command=self.step_1)
step_1_button.grid(row=10, column=0, sticky="EW")
def step_1(self):
# `self.master` gives access to parent object which here is `Masterframe` (because you used `Masterframe` as `self` when you created `ControlsFrame(self)`
periode_2 = self.master.user_input_frame.get_period() # without `self` in `get_period()`
print("step 1")
class ButtonFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
quit_button = ttk.Button(self, text="Quit", command=self.quit)
quit_button.grid(row=4, column=1, sticky="EW")
def quit(self):
app.destroy()
app = Mainframe()
app.mainloop()
BTW: in ButtonFrame you forgot self. in command=self.quit and () in app.destroy()
EDIT: as #acw1668 noticed function get_period() doesn't return value from entry - it only print it - so it needs return
def get_period(self):
return self.entry_year.get()

Related

how to get a value out of a class's init function python

I am working with tkinter's class-based structure and I need to get a value of text input. How do I do that?
Here is the relevant code:
#GUI
class PseudostreamWidget(tk.Frame):
def __init__(self, master=None, **kw):
tk.Frame.__init__(self, master, **kw)
self.targetIP = tk.Entry(self.Ipconfig)
self.targetIP.configure(background='black', font='{Lato} 12 {}', foreground='white', highlightbackground='black')
self.targetIP.configure(highlightcolor='black', justify='left', relief='raised')
_text_ = '''Friend's Public IP Here'''
self.targetIP.delete('0', 'end')
self.targetIP.insert('0', _text_)
self.targetIP.grid(column='1', row='0')
#
#
#
target_ip = self.targetIP
#
#
How do I get it to print target_ip outside the class?
if __name__ == '__main__':
root = tk.Tk()
widget = PseudostreamWidget(root)
widget.pack(expand=True, fill='both')
root.mainloop()
print(target_ip)
Try this:
import tkinter as tk
class PseudostreamWidget(tk.Frame):
def __init__(self, master=None, callback=None, **kwargs):
super().__init__(master, **kwargs)
self.targetIP = tk.Entry(self, fg="white", justify="left",
relief="raised", highlightbackground="black",
highlightcolor="black", bg="black",
insertbackground="white", font=("Lato", 12))
# self.targetIP.delete(0, "end") # No need for this
self.targetIP.insert(0, "Friend's Public IP Here")
self.targetIP.grid(column=1, row=0)
self.targetIP.bind("<Return>", callback)
def submit_data(event=None):
print("You typed in:", widget.targetIP.get())
root = tk.Tk()
widget = PseudostreamWidget(root, callback=submit_data)
widget.pack()
root.mainloop()
To use it just write something inside the entry and press the Enter key on your keyboard.
It passes in a function (submit_data) and binds to it.

Tkinter Python- function which can access data from other tabs

I would like to create a function in Main_Application which would access data from other tabs... how can i achieve it?
I was trying to access it by typing "Page_2.entry2.insert(0, "test")" but it returns Attribute error
I would appreciate any kind of help as i am struggling with it for some time already
class Main_Application(tk.Tk):
def __init__(self):
super().__init__()
self.title("HAT")
first_label = ttk.Label(self, text="lol").pack()
#Notebook
nb = ttk.Notebook(self)
nb.pack()
#Frames
p1 = tk.Frame(nb)
p2 = tk.Frame(nb)
p3 = tk.Frame(nb)
p4 = tk.Frame(nb)
nb.add(p1, text="Page1")
nb.add(p2, text="Page2")
nb.add(p3, text="Page3")
nb.add(p4, text="Page4")
Page_1(p1).pack()
Page_2(p2).pack()
def load_it_all(self):
print(Page_01(self).user_input.get())
Page_02.entry2.insert(0, "test")
# <HERE I WOULD LIKE TO CALL THE DATA FROM
#First one prints the data from Page_01 and second i would like to insert data in Page_02.entry2
class Page_1(ttk.Frame):
def __init__(self, container):
super().__init__(container)
#Stringvar
self.user_input = tk.StringVar()
#Labels
label = ttk.Label(self, text="HU3: ")
#Entries
entry = ttk.Entry(self, textvariable=self.user_input)
#Inserts
entry.insert(0, "4500")
#Buttons
button = ttk.Button(self, text="Apply", command=lambda: Main_Application.load_it_all(self))
#Geo
label.pack()
entry.pack()
button.pack()
def test(self):
print(self.user_input.get())
class Page_2(ttk.Frame):
def __init__(self, container):
super().__init__(container)
self.user_input = tk.StringVar()
label = ttk.Label(self, text="Trend from last cycle ")
#Entries
entry2 = ttk.Entry(self, textvariable=self.user_input)
#Inserts
# self.entry2.insert(0, "4500")
#Buttons
# button = ttk.Button(self, text="Apply", command=self.test2)
#Geo
label.pack()
entry2.pack()
# button.pack()
Your issues included
improperly initiating super
too many containers
randomly using ttk widgets
poor understanding of scope
naming syntax errors
unnecessary vars
Below is a working example of what you are trying to do
import tkinter as tk, tkinter.ttk as ttk
class Main(tk.Tk):
def __init__(self):
#this is how to properly init a super
tk.Tk.__init__(self)
#make notebook fill display
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
#Notebook
nb = ttk.Notebook(self)
nb.grid(row=0, column=0, sticky='nswe')
#keep a reference to the pages
self.p1 = Page_1(self)
self.p2 = Page_2(self)
#tabs
nb.add(self.p1, text="Page 1")
nb.add(self.p2, text="Page 2")
def load_it_all(self):
#use the page references to access and share data
self.p2.input = self.p1.input
class Page_1(tk.Frame):
#property
def input(self):
return self.userinput.get()
#input.setter
def input(self, value):
self.userinput.delete(0, 'end')
self.userinput.insert(0, value)
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
tk.Label(self, text="HU3: ").grid(row=0, column=0)
self.userinput = tk.Entry(self)
self.userinput.grid(row=0, column=1)
self.input="4500"
tk.Button(self, text="Apply", command=master.load_it_all).grid(row=0, column=2)
class Page_2(tk.Frame):
#property
def input(self):
return self.userinput.get()
#input.setter
def input(self, value):
self.userinput.delete(0, 'end')
self.userinput.insert(0, value)
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
tk.Label(self, text="Trend from last cycle ").grid(row=0, column=0)
self.userinput = tk.Entry(self)
self.userinput.grid(row=0, column=1)
if __name__ == "__main__":
root = Main()
root.geometry('800x600')
root.title("HAT")
root.mainloop()

Python 3 - Tkinter nameError

NameError: name 'onOpen' is not defined
There is something wrong with the command function. I am not sure what I did wrong here. I had the code tested before the onOpen function and it works fine.
import tkinter as tk
from tkinter import filedialog
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()
def onOpen():
""" Ask the user to choose a file and update the values of label change button"""
button_label.set(filedialog.askopenfilename(filetypes = ()))
def createWidgets(self):
#instruction label
self.labelInstruct = tk.Label(self, text="Instructions:", padx=10, pady=10)
self.labelInstruct = tk.Label(self, text="All you have to do is insert the file and save it.\n The conversion is instant", padx=10, pady=10)
self.labelInstruct.pack()
#insertfile button
self.ifbut = tk.Button(self, text="Insert File", command=onOpen)
self.ifbut.pack()
button_label = tk.StringVar(self)
text = tk.Label(self, textvariable = button_label)
text.pack()
#save button
self.saveLabel = tk.Label(self, text="Save File", padx=10, pady=10)
self.saveLabel.pack()
self.saveButton = tk.Button(self)
self.saveButton.pack()
#quit button
self.quitButton = tk.Button(self, text='Quit',
command=self.quit)
self.quitButton.pack()
app = Application()
app.master.title('Sample application')
app.mainloop()
Seeing that there are many problems with the way this code is written I am only going to point out a few of them and tackle the main question from the OP.
Lets start with the fact that you need to define the main window with something like root = tk.Tk() and you also need to make sure all your methods in your class have the argument self as the first argument.
Also any variable you are defining also should have self so that the class can interact with it. This (button_label) for example should be self.button_label.
There is no reason to use return the way you are trying to in the onOpen(self): method. Return does not work like that. Return is there so you can return a value to something that is calling the function/method to be used for something else and is not for setting the value of something.
Note that I also add the root window variable to the app = Application(root) line. This lets us pass the main window into the class.
all and all the following should work for the onOpen(self): function but the rest still needs some work.
import tkinter as tk
from tkinter import filedialog
class Application(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.parent = parent
self.pack()
self.createWidgets()
def onOpen(self):
""" Ask the user to choose a file and update the values of label change button"""
self.button_label.set(filedialog.askopenfilename(filetypes = ()))
def createWidgets(self):
#instruction label
self.labelInstruct = tk.Label(self.parent, text="Instructions:", padx=10, pady=10)
self.labelInstruct = tk.Label(self.parent, text="All you have to do is insert the file and save it.\n The conversion is instant", padx=10, pady=10)
self.labelInstruct.pack()
#insert file button
self.ifbut = tk.Button(self.parent, text="Insert File", command = self.onOpen)
self.ifbut.pack()
self.button_label = tk.StringVar()
self.text = tk.Label(self.parent, textvariable = self.button_label)
self.text.pack()
#save button
self.saveLabel = tk.Label(self.parent, text="Save File", padx=10, pady=10)
self.saveLabel.pack()
self.saveButton = tk.Button(self.parent, text = "Save")
self.saveButton.pack()
#quit button
self.quitButton = tk.Button(self.parent, text='Quit', command=self.quit)
self.quitButton.pack()
root = tk.Tk()
app = Application(root)
app.master.title('Sample application')
app.mainloop()
You need to return the function value as below:
def onOpen():
""" Ask the user to choose a file and update the values of label change button"""
return button_label.set(filedialog.askopenfilename(filetypes = ()))

Creating a custom widget in tkinter

I want to create a custom widget in tkinter such that when instantiated, displays a label and an entry box. Example I created a class named entry and call as.. entry ('name', master ) and this would display a label with text as main along side an entry box.
I have succeeded in doing that but my problem is with the geometry managers. they all seem to mess up everything
Your widget should subclass Frame. Within the frame you can use any geometry manager you want without affecting any other code. It's important that the widget class does not call grid, pack or place on itself -- that's the job of the function that creates the widget. Every widget, or function that creates a widget, should only ever worry about laying out its children.
Here's an example that creates a couple of different custom widgets. Each uses a different geometry manager to illustrate that they don't interfere with each other:
try:
# python 3.x
import tkinter as tk
except ImportError:
# python 2.x
import Tkinter as tk
class CustomWidget(tk.Frame):
def __init__(self, parent, label, default=""):
tk.Frame.__init__(self, parent)
self.label = tk.Label(self, text=label, anchor="w")
self.entry = tk.Entry(self)
self.entry.insert(0, default)
self.label.pack(side="top", fill="x")
self.entry.pack(side="bottom", fill="x", padx=4)
def get(self):
return self.entry.get()
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.label = tk.Label(self)
self.e1 = CustomWidget(self, "First Name:", "Inigo")
self.e2 = CustomWidget(self, "Last Name:", "Montoya")
self.submitButton = tk.Button(self, text="Submit", command=self.submit)
self.e1.grid(row=0, column=0, sticky="ew")
self.e2.grid(row=1, column=0, sticky="ew")
self.label.grid(row=2, column=0, sticky="ew")
self.submitButton.grid(row=4, column=0)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(2, weight=1)
def submit(self):
first = self.e1.get()
last = self.e2.get()
self.label.configure(text="Hello, %s %s" % (first, last))
if __name__ == "__main__":
root = tk.Tk()
Example(root).place(x=0, y=0, relwidth=1, relheight=1)
root.mainloop()
I agree with Mr. Oakley. You should subclass frame to do your job.
The simplest way to do what you want is to create a module with the following code:
# AnnotatedEntry.py
def AnnotatedEntry(master, name="An annoted entry box"):
'''
As a little extra, name is a keyword-argument, which defaults to "An annotated
entry box."
'''
import tkinter as tk
overlord = tk.Frame(master, height=5, width=40)
labeller = tk.Label(overlord, text=name, font="Times 14 bold")
labeller.grid(sticky='new')
inputter = tk.Entry(overlord, font="Times 14 bold")
inputter.grid(sticky='sew', pady=(10,0))
return overlord
This would be used as follows:
# Main program
import tkinter
import AnnotatedEntry
root = tkinter.Tk()
hold = AnnotatedEntry.AnnotatedEntry(root, name="Hello, world!")
hold.grid()
I hereby affirm, on my Scout Honor, that this code has been fully tested, and is guaranteed to work in Python 3.7.4. That being said, there is currently no method for returning the data contained in the Entry; you will have to work that out for yourself.
Based on #Bryan Oakley answer, I do have some modification. I know it's out of topic somehow. This is how to return a value from the widget and it only allows integer up to some number of digits that the user must entered.
#create a global value
global tbVal
tbVal = 0
class CustomWidget(tk.Frame):
def __init__(self, parent, nDigits):
tk.Frame.__init__(self, parent)
self.entry = tk.Entry(self)
self.entry.pack(side="bottom", fill="x", padx=4)
self.entry.configure(validate='all',validatecommand=windows.register(self.sbValidate),'%P','%W',nDigits))
def get(self):
return self.entry.get()
def sbValidate(self, userInput, widget, nDigits):
global tbVal
tbVal = userInput
if userInput == '':
return True
if '.' in userInput or ' ' in userInput:
return False
n = len(userInput)
if n > int(nDigits):
return False
try:
val = int(float(userInput))
except ValueError:
return False
return val
class Example(tk.Frame):
def __init__(self, parent, nDigitsLimit):
tk.Frame.__init__(self, parent)
self.e1 = CustomWidget(self, nDigitsLimit)
self.e1.grid(row=0, column=0, sticky="ew")
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(2, weight=1)
def btnStartClick():
print(tbVal)
nDigitsLimit = 8
tbTest = ttk.Entry(Example(windows, nDigitsLimit).place(x=20, y=20, relwidth=0.25, relheight=0.05))
btnStart = tk.Button(frame, text='Start', command=btnStartClick)
btnStart.place(relx=0.50, rely=0.50)

Trace radiobutton value defined in child class and pass it to parent class in Python

I am new to Python and Tkinter so unable to figure out which might be the simplest thing to do. Could someone please check the below code and tell me how can I trace value returned by radiobutton defined in child class and pass it to parent class. I get following error after compiling:
AttributeError: Toplevel instance has no attribute 'trace_fun'
I am not sure why am I getting this error since I have defined trace_fun in child class body. I have successfully traced variables in parent class but getting above error while trying to do it in the child class.
from Tkinter import *
class Parent(Frame):
classvar = 0
def __init__(self):
Frame.__init__(self)
self.master.title("Parent WIndow")
self.master.geometry("200x100")
self.grid()
self._button = Button(self, text="Create", width=10, command=self.new_window)
self._button.grid(row=0, column=0, sticky=E+W)
def new_window(self):
self.new = Child()
class Child(Parent, Frame):
def __init__(self):
Parent.__init__(self)
new = Frame.__init__(self)
new = Toplevel(self)
new.title("Child Window")
new.grid()
new._var = IntVar()
new._var.set(0)
new._var.trace("w", new.trace_fun)
new._radioButton = Radiobutton(new, text = "Option 1", variable = new._var, value = 1)
new._radioButton.grid(row=0, column=0, sticky=W, padx=10, pady=10)
new._radioButton2 = Radiobutton(new, text = "Option 2", variable = new._var, value = 2)
new._radioButton2.grid(row=1, column=0, sticky=W, padx=10, pady=10)
new._button = Button(new, text = 'Ok', command=new.destroy)
new._button.grid(row=2, column=0, pady=10)
def trace_fun(new, *args):
print new._var.get()
Parent.classvar = new._var.get()
obj = Parent()
def main():
obj.mainloop()
main()
You've overwritten your new variable here:
new = Frame.__init__(self)
new = Toplevel(self)
After those two statements execute, new is equal to an instance of the Toplevel class.
Next, this code executes:
new._var.trace("w", new.trace_fun)
and in particular:
new.trace_fun
So, you have a Toplevel instance trying to access an attribute named trace_fun. The error message is telling you that the Toplevel class does not have any attribute named trace_fun.
Edit:
You can't call trace_fun on a Toplevel instance--ever. Nor can you call trace_fun on a Parent instance--ever. So print out a copy of your program, then get a pen and circle all the variables that are Toplevel instances; then circle all the variables that are Parent instances. You can't call trace_fun on any of those variables. Alternatively, circle all the variables that are Child instances. You can call trace_fun on those variables.
Here is an example of what you can do:
class Child:
def do_stuff(self): #1) self is an instance of class Child, i.e. the object that is calling this method
self.trace_fun() #2) The Child class defines a method named trace_fun()
#3) Therefore, self can call trace_fun()
x = self.trace_fun #4) ...or you can assign self.trace_fun to a variable
#5) ...or pass self.trace_fun to another function
def trace_fun(self):
print 'hello'
d = Chile()
d.do_stuff()
--output:--
hello
It doesn't look like you have a Parent/Child relationship between your two frames--because the Child frame doesn't use anything inherited from the Parent frame. So you could just create two separate frames for your app. Here is an example:
import Tkinter as tk
class EntryFrame(tk.Frame):
classvar = 0
def __init__(self, root):
tk.Frame.__init__(self, root) #Send root as the parent arg to Frame's __init__ method
root.title("Parent Window")
root.geometry("400x200")
tk.Label(self, text="First").grid(row=0)
tk.Label(self, text="Second").grid(row=1)
e1 = tk.Entry(self)
e2 = tk.Entry(self)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
button = tk.Button(self, text="Create", width=10, command=self.create_new_window)
button.grid(row=2, column=0, sticky=tk.E + tk.W)
self.grid()
def create_new_window(self):
RadioButtonFrame()
class RadioButtonFrame(tk.Frame):
def __init__(self):
new_top_level = tk.Toplevel()
tk.Frame.__init__(self, new_top_level) #Send new_top_level as the parent arg to Frame's __init__ method
new_top_level.title("Radio Button Window")
new_top_level.geometry('400x300+0+300') # "width x height + x + y"
self.int_var = int_var = tk.IntVar()
int_var.trace("w", self.trace_func)
int_var.set(0)
rb1 = tk.Radiobutton(self, text = "Option 1", variable = int_var, value = 1)
rb1.grid(row=0, column=0, sticky=tk.W, padx=10, pady=10)
rb2 = tk.Radiobutton(self, text = "Option 2", variable = int_var, value = 2)
rb2.grid(row=1, column=0, sticky=tk.W, padx=10, pady=10)
button = tk.Button(self, text = 'Ok', command=new_top_level.destroy)
button.grid(row=2, column=0, pady=10)
self.grid()
def trace_func(self, *args):
radio_val = self.int_var.get()
print radio_val
EntryFrame.classvar = radio_val
def main():
root = tk.Tk()
my_frame = EntryFrame(root)
root.mainloop()
main()
By making slight changes, now my code is working perfectly. Posting new code for someone stuck on the same point as me earlier. Changes can be seen in the below code:
import Tkinter as tk
class Parent:
classvar = 0
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master)
self.master.title("Parent Window")
self.master.geometry("400x100")
self.frame.grid()
self._button = tk.Button(self.frame, text="Create", width=10, command=self.new_window)
self._button.grid(row=0, column=0, sticky=tk.E+tk.W)
def new_window(self):
self.child_window = tk.Toplevel(self.master)
self.app = Child(self.child_window)
class Child(Parent):
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master)
self.master.title("Child Window")
self.frame.grid()
self._var = IntVar()
self._var.set(0)
self._var.trace("w", self.trace_fun)
self._radioButton = tk.Radiobutton(self.frame, text = "Option 1", variable = self._var, value = 1)
self._radioButton.grid(row=0, column=0, sticky=W, padx=10, pady=10)
self._radioButton2 = tk.Radiobutton(self.frame, text = "Option 2", variable = self._var, value = 2)
self._radioButton2.grid(row=1, column=0, sticky=W, padx=10, pady=10)
self._button = tk.Button(self.frame, text = 'Ok', command=self.master.destroy)
self._button.grid(row=2, column=0, pady=10)
def trace_fun(self, *args):
Parent.classvar = self._var.get()
print Parent.classvar
root = tk.Tk()
obj = Parent(root)
def main():
root.mainloop()
main()

Categories

Resources