I've been trying to get an entry value (the S1 in the code) to set itself as a value (STR in the _attributes dictionary), and I just can't get it to work. I want to make this an eventual toploop, but am going a step at a time on this, as I'm new to programming in general. Am I going about this the right way, or should I just have a button that, when pressed, does a lookup on the entry value at that time and goes with it, instead? I've gone through several tutorials and lessons I've found online for Tkinter, but still seem to be miles away from being able to make anything work the way I expect it to.
#! usr/bin/python27
from Tkinter import *
class Character:
def __init__(self, **kvargs):
self._attributes = kvargs
def set_attributes(self, key, value):
self._attributes[key] = value
return
def get_attributes(self, key):
return self._attributes.get(key, None)
def attrInput(stat, x, y):
"""Creates a label for entry box"""
L = Label(B,
width = 5,
relief = RIDGE,
anchor = E,
text = stat).grid(row = x,
column = y)
B = ""
def main():
Person = Character()
B = Tk()
S1 = Entry(B, width = 3)
S1.grid(row = 0, column = 1)
S1.bind("<Key>", Person.set_attributes('STR', S1.get()) )
attrInput("Str: ", 0, 0)
Button(B, text='Quit', command=B.destroy).grid(row=3, column=0, sticky=W, pady=4)
B.mainloop()
print Person.__dict__
if __name__ == '__main__': main()
new code (seems to be working, I'm getting what I want out of it, at least). I'll have to modify it slightly to make it a toploop, but here's the foundation
class Character:
def __init__(self, **kvargs):
self._attribute = kvargs
def set_attribute(self, key, value):
self._attribute[key] = value
return
def get_attribute(self, key):
return self._attribute.get(key, None)
class attrAsk:
def __init__(self, master, Char, attrName, Row, Column):
self.Char = Char
self.attrName = attrName
attrInput(attrName+":", Row, Column)
self.e = Entry(master, width = 3)
self.e.grid(row = Row, column = Column+1)
self.e.bind("<KeyRelease>", self.set_attr)
def set_attr(self, event):
self.Char.set_attribute(self.attrName, self.e.get())
def attrInput(stat, x, y):
"""Creates a label for entry box"""
L = Label(box,
width = 5,
relief = RIDGE,
anchor = E,
text = stat).grid(row = x,
column = y)
Person= Character()
box = Tk()
STRENT = attrAsk(box, Person, "STR", 0, 0)
DEXENT = attrAsk(box, Person, "DEX", 1, 0)
CONENT = attrAsk(box, Person, "CON", 2, 0)
INTENT = attrAsk(box, Person, "INT", 3, 0)
WISENT = attrAsk(box, Person, "WIS", 4, 0)
CHAENT = attrAsk(box, Person, "CHA", 5, 0)
Button(box,
text='Continue',
command=box.destroy).grid(columnspan = 2,
row=8,
column=0,
sticky=W,
pady=4)
box.mainloop()
print Person.__dict__
Change the line:
S1.bind("<Key>", Person.set_attributes('STR', S1.get()) )
to something like:
def key_pressed(event):
Person.set_attributes('STR', S1.get())
S1.bind("<KeyRelease>", key_pressed)
There are two reasons the original code doesn't work:
bind takes a function as its second argument- that function is then called when the event occurs. The expression Person.set_attributes('STR', S1.get()) as you use it, however, just happens immediately. You need to put that expression into a function so that it happens only when the key is pressed.
<Key> means the event occurs when the key is first pressed, but you would rather it happen when the key is released (and therefore the new character has been added). You thus want to use <KeyRelease>.
One other note: it would be a good idea to organize all your functionality, especially the callback methods, into a class. For example:
class Window(object):
def __init__(self):
self.person = Character()
self.B = Tk()
self.S1 = Entry(B, width = 3)
self.S1.grid(row = 0, column = 1)
self.S1.bind("<KeyRelease>", self.key_pressed)
attrInput("Str: ", 0, 0)
self.button = Button(B, text='Quit', command=self.B.destroy).grid(row=3, column=0, sticky=W, pady=4)
self.B.mainloop()
print self.person.__dict__
def key_pressed(self, event):
self.person.set_attributes('STR', self.S1.get())
def main():
w = Window()
if __name__ == '__main__': main()
The benefit of this organization might not be immediately apparent, but it becomes very useful once you have a large number of callback methods and are keeping track of a large number of widgets.
In response to your comment, you can create both the Entry and the Label objects in a for loop, each on its own row. The key_pressed method can then learn the field and the input text from the event object that gets passed to it, as seen here (try it):
class Window(object):
def __init__(self):
self.person = Character()
self.B = Tk()
self.fields = ["STR", "DEX", "CON", "INT", "WIS", "CHA"]
self.inputs = {}
for i, f in enumerate(self.fields):
self.inputs[f] = Entry(B, width = 3)
self.inputs[f].grid(row=i, column=1)
self.inputs[f].bind("<KeyRelease>", self.key_pressed)
attrInput(f + ":", i, 0)
self.button = Button(B, text='Quit', command=self.B.destroy).grid(row=7, column=0, sticky=W, pady=4)
self.B.mainloop()
print self.person.__dict__
def key_pressed(self, event):
field = self.fields[int(event.widget.grid_info()["row"])]
self.person.set_attributes(field, event.widget.get())
Related
I was wondering how to calculate stuff using tkinter buttons. I'm making a simple program to calculate seconds to hours:minutes:seconds. The user inputs an integer using the entry widget on the seconds box and when they press calculate, they get the result via the converted time line. I'm confused on how to start calculating it. I know you get the integer via .get, but I'm stuck on how to do that and calculate it in a h:m:s format. This is my code so far.
import tkinter
from tkinter import *
class TimeConverterUI():
def __init__(self):
self.root_window = Tk()
self.root_window.geometry('400x150')
self.root_window.title('Seconds Converter')
self.text()
self.calculate_button()
self.quit_button()
self.root_window.wait_window()
def text(self):
row_label = tkinter.Label(
master = self.root_window, text = 'Seconds: ')
row_label.grid( row = 0, column = 0, columnspan=2, padx=10, pady=10,
sticky = tkinter.W)
secondsEntry = Entry(master = self.root_window)
secondsEntry.grid(row = 0, column = 1)
row_label = tkinter.Label(
master = self.root_window, text = 'Converted Time(H:M:S): ').grid(row=1)
def calculate_button(self):
quit = Button(self.root_window, text = "Calculate", command = self.calculate)
quit.grid(row = 3, column = 0, columnspan = 3, pady=20,
sticky = tkinter.W)
def calculate(self):
pass
def quit_button(self):
quit = Button(self.root_window, text = "Quit", command = self.quit)
quit.grid(row = 3, column = 3, columnspan = 3, pady=20,
sticky = tkinter.E)
def quit(self) -> bool:
self.root_window.destroy()
return True
if __name__ == '__main__':
convert=TimeConverterUI()
First break this code below into 2 lines if you ever want to use row_label later because this will return NoneType. You should define it first then use .grid on it (just like your button).
row_label = tkinter.Label(
master = self.root_window, text = 'Converted Time(H:M:S): ').grid(row=1)
Now you can create another label to show the result. Remember to put self. before its name so you can use it in the calculate function. Also change secondsEntry to self.secondsEntry for the same reason.Now you just use int(self.secondsEntry.get()) in that function and do the required calculations. Then set the result to that result label with .configure(text=str(result))
I really need help with some code. I don't expect you to write it for me, since it is a school project, but I am just really lost and need help.
The code I am writing is some sort of production system.
It doesn't need to actually be able to send a task anywhere, since this is just an imagined scenario.
The code has to consist of three files: data.py, model.py and gui.py.
Gui can access the two other files
Data can only access model
Model can't access either of the other two.
My teacher had written some of the code witch I have continued on. Some of the text is in danish, but most comments are in English.
The code is as follows.
data.py
from model import *
class Data(object):
def __init__(self):
self.units = []
self.finished_tasks = []
def __str__(self):
result = "These tasks have been finished: "
for i in self.finished_tasks:
result += str(i)
return result
def task_done(self, unit):
done_task = unit.task_done()
if done_task != None:
#TODO: add to list of finished tasks
pass
def add_task(self, name, amount, unit):
s = Springroll_task(name, amount)
unit.add_to_queue(s)
def read_from_database(self):#doesn't actually read from db..
self.units.append(Production_unit("maskine1"))
self.units.append(Production_unit("maskine2"))
self.add_task("Miniruller", 100, self.units[0])
self.add_task("Maxiruller", 200, self.units[0])
self.add_task("HowIRoll", 3000, self.units[0])
self.add_task("RulleMarie", 40, self.units[1])
self.add_task("Rullesten", 500, self.units[1])
self.add_task("Toiletpapirsruller", 6000, self.units[1])
model.py
class Springroll_task(object):
def __init__(self, name, amount):
self.name = name
self.amount = amount
def __str__(self):
return self.name + " " + str(self.amount)
class Production_unit(object):
def __init__(self, amount={}, name={},):
#name of the production unit
self.name = name
self.amount = amount
#the current task
self.current_task = None
#the tasks in the queue
self.springroll_queue = []
#the size of the queue
self.queue_size = 0
def __str__(self):
#TODO
return self.name + " " + str(self.amount)
def add_to_queue(self, task={}):
if self.current_task == None:
self.current_task = task
else:
self.springroll_queue.append(task)
self.queue_size += 1
#remember to update queue_size
pass
def task_done(self):
#TODO: remember the old current task.
#Set the current task to be the first in the queue (and remove from queue)
# - if there is a task in the queue.
#return the old current task.
#remember to update queue_size
self.queue_size -= 1
pass
gui.py
from tkinter import *
from model import *
from data import Data
class Application(Frame):
def __init__(self, master, unit):
self.mod = Production_unit()
super(Application, self).__init__(master)
self.grid()
self.unit = unit
self.create_widgets()
def create_widgets(self):
self.unit_name_lbl = Label(self, text = self.unit.name)
self.unit_name_lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.cur_prod_lbl = Label(self, text = "produktion nu: ")
self.cur_prod_lbl.grid(row = 1, column = 0, columnspan = 2, sticky = W)
self.prod_lbl = Label(self, text = "produkt")
self.prod_lbl.grid(row = 2, column = 0, sticky = W)
self.amount_lbl = Label(self, text = "antal")
self.amount_lbl.grid(row = 2, column = 1, sticky = W)
#Label for production now
self.amount1_lbl = Label(self, text = " ", bg ="red")
self.amount1_lbl.grid(row = 3, column = 0, sticky = W)
self.amount2_lbl = Label(self, text = " ", bg ="red")
self.amount2_lbl.grid(row = 3, column = 1, sticky = W)
#Button for task finished
self.finished_but = Button(self, text = "Opgave afsluttet", bg ="pink", command=self.mod.task_done)
self.finished_but.grid(row = 3, column = 2, sticky = W)
#Label for queue
self.queue_lbl = Label(self, text = "Kø")
self.queue_lbl.grid(row = 4, column = 0, sticky = W)
#Label for production queue
for i in range(0,3):
self.name_lbl =Label(self, text = self.mod.springroll_queue, bg="red", width= 6)
self.name_lbl.grid(row = 5+i, sticky = W)
for j in range(0,3):
self.qt_lbl =Label(self, text = self.mod.springroll_queue, bg="red", width= 4)
self.qt_lbl.grid(row = 5+j, column = 1)
self.new_lbl = Label(self, text = "Ny")
self.new_lbl.grid(row = 10, column = 0, sticky = W)
#Entry for entries
self.eq1_ent = Entry(self, text = "", width=6)
self.entry_name = self.eq1_ent.get()
self.eq1_ent.grid(row = 11, sticky = W)
self.ea1_ent = Entry(self, text = "", width=4)
self.ea1_ent.grid(row = 11, column = 1, sticky = W)
#Button for add to queue
self.add_but = Button(self, text = "Tilføj til kø", bg ="pink", command=self.mod.add_to_queue(self.ea1_ent.get()))
self.add_but.grid(row = 11, column = 2, sticky = W)
def done(self):
d.task_done(self.unit)
self.redraw()
def add(self):
n = "Nyt navn" #read from gui
a = "Nyt antal" #read from gui
d.add_task(n, a, unit)
self.redraw()
def redraw(self):
#TODO
pass
# main
root = Tk()
root.title("Daloon")
root.geometry("300x300")
d = Data()
d.read_from_database()
p = d.units[0]
app = Application(root, p)
root.mainloop()
So it currently looks like this:
What I need to be able to do is to take an input in the bottom two entry widgets and put them in one of the 4 label widgets above, beginning from the top and then in the queue afterwards, this should happen when I press the button add_but, which seems to be gone currently.
After that I need the task stored in the data file when the "Opgave afsluttet" button is pressed.
I really hope someone is able to help me!
I edited it with some suggestions, and am calling the right self.eq1_ent.get() now, I think. I dont get any error any longer, now I just don't really know how to make it do what I want.
Edit 2: I am slowly getting some stuff, so i have made changes in the model.py and gui.py...
It looks like this now:
self.eq1 is not defined. you have self.q1_lbl and self.eq1_ent.
To access the label use self.q1_lbl.
To be able to set text to your label create them as following:
self.var = StringVar()
self.unit_name_lbl = Label(self, textvariable=self.var)
For example, from redraw() you can set 'text' to self.unit_name_lbl like this : self.var.set('text').
Check if you missed self in d.add_task(n, a, unit)
When you do command=mod.add_to_queue(self.ea1_ent.get()) the mod.add_to_queue function will be called directly, if you want to pass argument to this function when user press the button, you can use lambda:
command=lambda: mod.add_to_queue(self.ea1_ent.get)
I am trying to create a simple Tkinter user registration app and have run into a problem. I want to get the input from an Entry to another function.
My code as of now:
from Tkinter import *
def addUsr():
username = sv.get() #here
password = sv1.get() #here
page = open("Users.txt", 'r+')
contents = page.read()
page.write("--->")
page.write("\n")
page.write("username: " + username)
page.write("\n")
page.write("password: " + password)
page.write("\n")
page.write("<---")
page.write("\n")
page.close()
print contents
def reg():
usrs = Tk()
usrs.title("Text")
usrs.geometry('450x300+200+200')
sv = StringVar()
sv1 = StringVar()
ent1 = Entry(usrs, textvariable=sv).pack()
ent2 = Entry(uses, textvariable=sv1).pack
button1 = Button(usrs, text="submit", command=addUsr).pack(side='bottom', padx=15, pady=15)
usrs.mainloop()
I want to get the sv and sv1 into the addUsr function, but this code returns the error message:
username = sv.get()
NameError: global name 'sv' is not defined
When the code is built up so that the second function is not a function this code works. I just want to find a way to get the same result but using this structure. How do you suppose I do this?
I think this is a structural problem. You normally would use a class to create the application and put everything under that class. Then accessing functions and variables from anywhere is straightforward. I have created a simple example because I do not have time to rewrite all of your code!
from Tkinter import *
class Application(Frame): # create a class to hold the application within
def __init__(self, master): # boot it up
""" Initialize the frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()
self.var1 = "var1"
self.var2 = "var2"
def create_widgets(self): # create the GUI interface
self.lbl = Label(self, text = "xxxx")
self.lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W, pady = 4)
self.input = Text(self, width = 35, height = 5, wrap = WORD)
self.input.grid(row = 1, column = 0, columnspan = 2, sticky = W)
self.submit_button = Button(self, text = "submit", command = self.functionX)
self.submit_button.grid(row = 2, column = 0, columnspan = 2, sticky = W)
def functionX(self):
print "do some stuff"
self.var3 = "yet another variable" # create a variable in one function for access in another
self.functionY() # call one function from another function
def functionY(self):
print "do something else"
print self.var1 # access some class variables
print self.var2
print self.var3
root = Tk()
root.title("xxxxxxxxxxxx")
root.geometry("330x310")
app = Application(root)
I hope this helps, it is pretty self explanatory when you run the code and read it to understand what is going on. (by the way I ended up using PyQt/Pyside with QtDesigner instead of Tkinter, you may want to check that out if you don't know about it already).
I have a problem with the following python script. Later, it will catch the data from a barcode scanner and display the text as a label. But whenever the text should be changed from the label (highlighted line), the program crashes. I am an absolute beginner Python and can not explain that. I comment out the line, the program works.
from Tkinter import *
import pyHook
class Application(Frame):
def __init__(self):
Frame.__init__(self)
self.master.title("Sc4nn0r")
self.variable = "Start Variable"
self.master.geometry("363x200")
self.master.resizable(0,0)
self.master.rowconfigure( 0, weight = 1)
self.master.columnconfigure( 0, weight = 1 )
self.grid( sticky = W+E+N+S )
self.label4String = StringVar()
self.label4 = Label(self, textvariable=self.label4String)
self.label4.grid( row = 2, column = 1, columnspan = 2, sticky = W+E+N+S)
self.label4String.set("Variable1")
self.string = ''
hook = pyHook.HookManager()
hook.KeyDown = self.read
hook.HookKeyboard()
def read(self, event):
print(event.Ascii);
if event.Ascii != 13:
self.string = self.string + chr(event.Ascii)
else:
self.post(self.string.strip(' \0'))
self.string = ''
return True
def post(self,string):
self.label4String.set(string) # THIS LINE I Mean ##########
print(string)
def main():
Application().mainloop()
if __name__ == '__main__':
main()
I hope it can someone help me.
I would suggest getting rid of StringVar in its entirety. Instead, use self.label4 = Label(self, text = "Variable1"). Then, whenever you wish to change the label, you can use self.label4.config(text = string).
I thought I know the fundamentals of python, but this problem seems to prove that wrong.
Problem is, when I pass a class to a function, that function will not recognize the class that I passed, but instead just recognize that parent class.
This is the class.
from tkinter import *
from one_sample_t_test_dialog import One_T_Test_Dialog
from about_us_dialog import About_Us_Dialog
class Gui(Frame):
def __init__(self, master):
Frame.__init__(self, master, background="white")
self._master = master
# Main Window
frame = Frame(master, width = 800, height = 600)
self._master.title("Statistics Program")
# Menus
menu = Menu(master)
master.config(menu=menu)
# --Tests
test_menu = Menu(menu)
menu.add_cascade(label = "Tests", menu = test_menu)
# ----T-Tests
t_test_menu = Menu(test_menu)
test_menu.add_cascade(label = "T-Tests", menu = t_test_menu)
t_test_menu.add_command(label="One Sample t-test", command = self.one_sample_t_test)
t_test_menu.add_command(label="Two Sample t-test", command = self.two_sample_t_test)
t_test_menu.add_command(label="Paired t-test", command = self.about_us)
# --Help
help_menu = Menu(menu)
menu.add_cascade(label = "Help", menu = help_menu)
help_menu.add_command(label="About Us", command = self.about_us)
# Toolbar
# --t-test
toolbar = Frame(master)
l = Label(toolbar, text="Mean Comparison:")
l.pack(side=LEFT, padx = 5, pady = 5)
b=Button(toolbar, text = "One Sample t-test", command=self.one_sample_t_test)
b.pack(side=LEFT)
b=Button(toolbar, text = "Two Sample t-test", command=self.two_sample_t_test)
b.pack(side=LEFT)
b=Button(toolbar, text = "Paired t-test", command=self.two_sample_t_test)
b.pack(side=LEFT)
# --anova
l=Label(toolbar, text="ANOVA:")
l.pack(side=LEFT, padx = 5, pady = 5)
b=Button(toolbar, text = "One Way Anova", command=self.two_sample_t_test)
b.pack(side=LEFT)
# --Multiple-comparison Tests
toolbar_02 = Frame(master)
l=Label(toolbar_02, text="Multiple Mean Comparison:")
l.pack(side=LEFT, padx = 5, pady = 5)
b=Button(toolbar_02, text = "Tukey", command=self.two_sample_t_test)
b.pack(side=LEFT)
b=Button(toolbar_02, text = "Bonferroni", command=self.two_sample_t_test)
b.pack(side=LEFT)
toolbar.pack(fill=BOTH)
toolbar_02.pack(fill=BOTH)
# Spreadsheet.
self.canvas = canvas = Canvas(self._master)
self.canvas_frame = canvas_frame = Frame(canvas)
# Scrollbars
vbar=Scrollbar(self._master,orient=VERTICAL, command=self.canvas.yview)
hbar=Scrollbar(self._master,orient=HORIZONTAL, command=self.canvas.xview)
# Further configuration
canvas.configure(yscrollcommand=vbar.set, xscrollcommand=hbar.set)
# Initialize scrollbars
vbar.pack(side=RIGHT,fill=Y)
hbar.pack(side=BOTTOM,fill=X)
canvas.pack(side=LEFT, expand=True, fill="both")
canvas.create_window((4,4), window=canvas_frame, anchor="nw")
canvas_frame.bind("<Configure>", self.OnFrameConfigure)
self.grid()
#canvas_frame.pack()
self._master.geometry("800x600+50+50")
#self.pack(fill=BOTH, expand=1)
def get_master(self):
return self._master
def OnFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
def about_us(self):
d = About_Us_Dialog(self._master)
root.wait_window(d.parent)
def grid(self):
"""
Make the grid here.
"""
grid_frame = self.canvas_frame
self.entry = []
for i in range(40):
self.entry.append([])
for i in range(len(self.entry)):
for j in range(80):
self.entry[i].append(Entry(grid_frame, width=10))
self.entry[i][j].grid(row=j, column=i)
# grid_frame.pack(padx=2, pady=2)
def one_sample_t_test(self):
d = One_T_Test_Dialog(self)
value = self._master.wait_window(d.parent)
# Check if an error occured.
result = None # We will store the result here.
if value is None:
return
else:
# perform the t-test here.
pass
# If we made it at this point, there's no error and
# the result have been acquired. We can now display
# the result.
def two_sample_t_test(self):
# Testing Ground
#print(self.get_variables())
#print(self.get_values(3))
pass
def get_variables(self):
"""
This method will return a dictionary of variable names and their corresponding
index, that is located in index zero of the double array. For instance,
self.entry[3][0] is a variable name, so is self.entry[5][0], and so on.
"""
variable_name_dict = {}
for i in range(len(self.entry)):
temp = self.entry[i][0].get()
if temp is not "":
variable_name_dict[i] = temp
return variable_name_dict
def get_values(self, variable_index):
"""
This method will return a list of values that is located under the variable.
Use this in conjunction with get_variables().
"""
values = []
if self.entry[variable_index][0] is not "": # Make sure that it's not empty.
for v in self.entry[variable_index]:
if v.get() is not "":
values.append(v.get())
# Since the first cell is in the column is always a variable name, we can
# pop the first element.
values.pop(0)
return values
root = Tk()
app = Gui(root)
root.mainloop()
This is the other class, with a method being called by the class above. the class above pass itself as an argument.
from tkinter import *
from tkinter import messagebox
import dialog
class One_T_Test_Dialog(dialog.Dialog):
def body(self, gui):
master = gui.get_master()
# Entry Labels.
Label(master, text="Mean:").grid(row=0)
Label(master, text="Standard Deviation:").grid(row=1)
Label(master, text="Sample Size:").grid(row=2)
Label(master, text="Sample Size:").grid(row=3)
Label(master, text="Test Value:").grid(row=4)
# Data entry class members.
# The for loop initialize the list as an entry list.
num_of_entry = 5
self.entry = [] #entry list
for i in range(num_of_entry):
self.entry.append(Entry(master))
# Data entry location initialization.
for i in range(num_of_entry):
self.entry[i].grid(row=i,column=1)
# Or, the user can just select a mean from the drop down list and
# enteryt the test value.
Label(master, text="Select Values Instead:").grid(column = 0, row=5)
self.dropdown_val = StringVar(master)
# initial value
self.dropdown_val.set('Select a values.')
choices = ['red', 'green', 'blue', 'yellow','white', 'magenta']
option = OptionMenu(master, self.dropdown_val, *choices).grid(column = 1, row=5)
button = Button(master, text="check value slected").grid(column=1, row=6)
# Further initialization.
# --At the Test Value, or null hypothesis, we want to have a default
# value. Assuming this is a 151/252 level course, the default value
# is always 0.
self.entry[4].insert(0, "0")
return self.entry[0] # initial focus
def apply(self):
# Collect the data first.
data_list = []
for e in self.entry:
data_list.append(e.get())
# Validate
for d in data_list:
# Make sure it's not empty.
# Make sure the value is float.
empty_flag = False
not_float_flag = False
if len(d) == 0:
empty_flag = True
if empty_flag is False:
try:
float(d)
except ValueError:
not_float_flag = True
if empty_flag is True or not_float_flag is True:
# Report an input error.
if empty_flag is True and not_float_flag is False:
messagebox.showerror("INPUT ERROR", "There's an empty input box.")
elif not_float_flag is True and empty_flag is False:
messagebox.showerror("INPUT ERROR", "Check your input. Make sure its a number.")
elif not_float_flag is True and empty_flag is True:
messagebox.showerror("INPUT ERROR", "There's an empty input box and non-numerical input.")
return None
# If everything went well, convert the validated data.
for i in range(len(data_list)):
data_list[i] = float(data_list[i])
return data_list
The problem is the line
master = gui.get_master()
in the second class gives an error because
AttributeError: 'Frame' object has no attribute 'get_master'
Frame being the parent of the class Gui.