I need to understand the concept behind the model/view/controller method and how to write a GUI that way. Here's just a really basic, simple GUI. Can someone explain to me how to rewrite this code using MVC?
from tkinter import *
class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create widgets to get story information and to display story. """
# create instruction label
Label(self,
text = "Enter information for a new story"
).grid(row = 0, column = 0, columnspan = 2, sticky = W)
# create a label and text entry for the name of a person
Label(self,
text = "Person: "
).grid(row = 1, column = 0, sticky = W)
self.person_ent = Entry(self)
self.person_ent.grid(row = 1, column = 1, sticky = W)
# create a label and text entry for a plural noun
Label(self,
text = "Plural Noun:"
).grid(row = 2, column = 0, sticky = W)
self.noun_ent = Entry(self)
self.noun_ent.grid(row = 2, column = 1, sticky = W)
# create a label and text entry for a verb
Label(self,
text = "Verb:"
).grid(row = 3, column = 0, sticky = W)
self.verb_ent = Entry(self)
self.verb_ent.grid(row = 3, column = 1, sticky = W)
# create a label for adjectives check buttons
Label(self,
text = "Adjective(s):"
).grid(row = 4, column = 0, sticky = W)
# create itchy check button
self.is_itchy = BooleanVar()
Checkbutton(self,
text = "itchy",
variable = self.is_itchy
).grid(row = 4, column = 1, sticky = W)
# create joyous check button
self.is_joyous = BooleanVar()
Checkbutton(self,
text = "joyous",
variable = self.is_joyous
).grid(row = 4, column = 2, sticky = W)
# create electric check button
self.is_electric = BooleanVar()
Checkbutton(self,
text = "electric",
variable = self.is_electric
).grid(row = 4, column = 3, sticky = W)
# create a label for body parts radio buttons
Label(self,
text = "Body Part:"
).grid(row = 5, column = 0, sticky = W)
# create variable for single, body part
self.body_part = StringVar()
self.body_part.set(None)
# create body part radio buttons
body_parts = ["bellybutton", "big toe", "medulla oblongata"]
column = 1
for part in body_parts:
Radiobutton(self,
text = part,
variable = self.body_part,
value = part
).grid(row = 5, column = column, sticky = W)
column += 1
# create a submit button
Button(self,
text = "Click for story",
command = self.tell_story
).grid(row = 6, column = 0, sticky = W)
self.story_txt = Text(self, width = 75, height = 10, wrap = WORD)
self.story_txt.grid(row = 7, column = 0, columnspan = 4)
def tell_story(self):
""" Fill text box with new story based on user input. """
# get values from the GUI
person = self.person_ent.get()
noun = self.noun_ent.get()
verb = self.verb_ent.get()
adjectives = ""
if self.is_itchy.get():
adjectives += "itchy, "
if self.is_joyous.get():
adjectives += "joyous, "
if self.is_electric.get():
adjectives += "electric, "
body_part = self.body_part.get()
# create the story
story = "The famous explorer "
story += person
story += " had nearly given up a life-long quest to find The Lost City of "
story += noun.title()
story += " when one day, the "
story += noun
story += " found "
story += person + ". "
story += "A strong, "
story += adjectives
story += "peculiar feeling overwhelmed the explorer. "
story += "After all this time, the quest was finally over. A tear came to "
story += person + "'s "
story += body_part + ". "
story += "And then, the "
story += noun
story += " promptly devoured "
story += person + ". "
story += "The moral of the story? Be careful what you "
story += verb
story += " for."
# display the story
self.story_txt.delete(0.0, END)
self.story_txt.insert(0.0, story)
# main
def main():
root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()
main()
ToyMVC "Toy MVC (Model View Controller) design" in the Tkinter docs is probably what you're looking for. I would personally design things a bit differently, but it mostly makes sense.
The key is separating out the model and view, and the controller is then all the bits that connect up a model and a view.
So, instead of having an Application with everything in it, you'd have these classes:
StoryModel: A model of a story.
StoryView: A window or other widget that you stick inside the frame—although in Tk, you can just as easily make it the frame itself.
StoryController: A class that, given a StoryModel and a StoryView, will tell its StoryView to create the appropriate widgets to display that story, and will then monitor both Model and View for changed and transmit them from one to the other.
Given that, you can create a simple Application that creates one StoryModel, one StoryView, one frame window to put the View in, and one StoryController to connect up the model and view.
For example, StoryModel could look like this:
class StoryModel(object):
body_parts = ['bellybutton', 'big toe', 'medulla oblongato']
def __init__(self):
self.person = ObservableStr('')
# ...
self.is_itchy = ObservableBool(False)
# ...
def tell(self):
story = "The famous explorer "
# ...
return story
And then you can get fancy and create an AlternateStoryView that displays the same information in a different way, and change the Application to create one of each view, and a controller for each, attached to the same model. For example, you might create a view that didn't use a grid, and instead automatically laid things out:
class AlternateStoryView(Frame):
def __init__(self, master):
super(StoryView, self).__init__(master)
def add_label(label):
label = Label(self, text=label)
label.pack()
return label
If you know about the trace method, you may notice that an Observable isn't really any different than using Tkinter.StringVar, etc. But the advantage (besides not having the clunky syntax of trace…) is that there's nothing Tkinter-specific about the model this way.
So, you can create a GtkStoryView or a CursesStoryView, without changing any of the code in the Model and Controller. (This doesn't quite work with ToyMVC, because things like addButton.config(command=self.addMoney) won't exactly translate to Gtk+ or curses unless you built a big Tk emulation layer… but you don't have to make that mistake in your design.)
Also, note that using Observable wrappers around all of your model variables is definitely not the only way to hook up a controller, or even necessarily the most Pythonic.
If you want to start/learn MVC web development using python language i suggest to get started with Django Framework
Related
I am trying to create a menu program in tkinter, where check boxes are created from items in a dictionary, then the total price of selected items is calculated when a button is clicked.
menu_items = {"Spam - £3" : 3, "Eggs - £7" : 7, "Chips - £1" : 1, "Beer - £2" : 2}
def widgets(self):
# create menu list
row = 1
for item in menu_items:
self.item = BooleanVar()
Checkbutton(self,
text = item,
variable = self.item
).grid(row = row, column = 0, sticky = W)
row += 1
calc_but = Button(self,
text = "Click to calculate",
command = self.calculate
).grid(row = row + 1, column = 0, sticky = W)
self.results_txt = Text(self, width = 20, height = 4, wrap = WORD)
self.results_txt.grid(row = row + 2, column = 0, columnspan = 2)
This creates check boxes, button and text display just fine, but my problem comes with my calculate method.
def calculate(self):
bill = 0
for item in menu_items:
if self.item.get():
bill += menu_items.get(item)
msg = "Total cost - £" + str(bill)
self.results_txt.delete(0.0, END)
self.results_txt.insert(0.0, msg)
It will add up everything (ticked or not), but only when the final check box is ticked. It displays 0 if the final item is not ticked.
I am not sure what my problem is, or if I am approaching this in the wrong way.
What's happening here
The way you create your buttons - by looping through each key in you dictionary - your program only references the last one you created, which it saves as self.item. When you call calculate(), it only checks and adds up this button's value.
One way around this is to save all the references to these Buttons in a table:
menu_items = {"eggs":7, "chips":1, "beer":2}
selected = {}
def calculate():
bill = 0
for item in menu_items:
if selected[item].get():
bill += menu_items[item]
results.delete(1.0, END)
results.insert(END, "Total cost - £" + str(bill))
for item in menu_items:
is_selected = BooleanVar()
button = Checkbutton(master, text=item, variable=is_selected)
button.grid(sticky="w")
selected[item] = is_selected
purchase_btn = Button(master, text="Calculate", command=calculate)
purchase_btn.grid()
results = Text(master, wrap=WORD)
results.grid(columnspan=2)
(I've omitted your class structure here. It is easy enough to re-incorporate it)
Now we're keeping a is_selected dictionary, so that we can track whether a button has been selected or not.
Its easy to reference this table, because the keys are the items themselves! Neat, not?
A couple more tips on tkinter:
If you're gridding in the next row every time, just call grid() with no col and row arguments - tkinter adds the row for you, and keeps the column.
It's best always to create a widget, store it as a variable, then grid this variable. Some people try to do this all in one, and then get confused when the try to reference their widget by this variable. They will find nothing, because the grid method returns nothing!
I hope this helped. Good luck!
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).
Hello guys im new to programming relatively, but all the same im trying to use a GUI interface to build a tip calculator. nothing big, nothing relatively hard, but im running into errors. for some reason my Python wont show the errors. it just goes to the shell, says SyntaxError: and then quits back to the script. it used to show the errors but i dont know whats wrong... anyways if you guys could help me troubleshoot this id greatly appreciate it..
`
# A tip calculator
# A tip calculator using a GUI interface
# Austin Howard Aug - 13 - 2014
from tkinter import *
#Creating buttons.
class Calculator(Frame):
""" A GUI tip calculator."""
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.creating_buttons()
def creating_buttons(self):
"""This list includes Entry fields, which the user will use to define
several objects such as Bill, and how many people are paying on that bill."""
#Create an entry field button for how much the bill total is.
#Create a label
bill_lbl = Label(self,
text = "Bill: ")
bill_lbl.grid(row = 1,
column = 0,
columnspan = 1,
sticky = W)
#Create an Entry field.
bill_ent = Entry(self)
bill_ent.grid(row = 1,
column = 1,
sticky = W)
#Create a Button for how many people will be paying on the bill
#Create label
people_paying_lbl = Label(self,
text = "How many people are paying on this bill?: ")
people_paying_lbl.grid(row = 2,
column = 0,
columnspan = 1,
sticky = W)
#Create an entry field
people_paying_ent = Entry(self)
people_paying_ent.grid(row = 2,
column = 1,
sticky = W)
#Create a text box to display the totals in
bill_total_txt = Text(self,
width = 40,
height = 40,
wrap = WORD)
bill_total_txt.grid(row = 3,
column = 0,
columnspan = 2,
sticky = W)
#Create a Submit button
submit = Button(self,
text = "Submit",
command = self.total)
submit.grid(row = 4,
column = 0,
sticky = W)
def total(self):
""" Takes the values from Bill, and # of people to get the amount that will be
displayed in the text box."""
TAX = .15
bill = float(bill_ent)
people = people_paying_ent
Total = ("The tip is: $", TAX * bill, "\nThe total for the bill is: $",
TAX * bill + bill,
"divided among the people paying equally is: $",
TAX * bill + bill / people "per, person.")
bill_total_txt.delete(0.0, END)
bill_total_txt.insert(0.0, Total)
#Starting the Program
root = Tk()
root.title("Tip Calculator")
app = Calculator(root)
root.mainloop()
`
You have an error on line 68:
Replace
TAX * bill + bill / people "per, person.")
with
TAX * bill + bill / people, "per, person.")
Also make sure you remove the backtick after root.mainloop()
Your way of getting the input from the Entry boxes is wrong. You should bind a StringVariable to them, to later be able to get what the user typed:
self.billvar = StringVar()
bill_ent = Entry(self, textvariable = self.billvar)
And the same for the number of people box.
Then in your total function you can read the values by using self.billvar.get(). You can convert this to a float using float(self.billvar.get()). However, when this fails (the user typed in something that can not be converted to a float) you probably want to tell them instead of having the program throwing an error. So you should use something like:
try:
convert input
except:
what to do if it fails, tell the user?
else:
what to do if it did not fail, so do the calculations
Your program then becomes something like this (I made comments with ##):
# A tip calculator
# A tip calculator using a GUI interface
# Austin Howard Aug - 13 - 2014
from tkinter import *
#Creating buttons.
class Calculator(Frame):
""" A GUI tip calculator."""
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.creating_buttons()
def creating_buttons(self):
"""This list includes Entry fields, which the user will use to define
several objects such as Bill, and how many people are paying on that bill."""
#Create an entry field button for how much the bill total is.
#Create a label
bill_lbl = Label(self,
text = "Bill: ")
bill_lbl.grid(row = 1,
column = 0,
columnspan = 1,
sticky = W)
#Create an Entry field.
## Create a StringVar and link it to the entry box
self.billvar = StringVar()
bill_ent = Entry(self, textvariable = self.billvar)
bill_ent.grid(row = 1,
column = 1,
sticky = W)
#Create a Button for how many people will be paying on the bill
#Create label
people_paying_lbl = Label(self,
text = "How many people are paying on this bill?: ")
people_paying_lbl.grid(row = 2,
column = 0,
columnspan = 1,
sticky = W)
#Create an entry field
## Create a StringVar and link it to the entry box
self.pplvar = StringVar()
people_paying_ent = Entry(self, textvariable = self.pplvar)
people_paying_ent.grid(row = 2,
column = 1,
sticky = W)
#Create a text box to display the totals in
## This had to be self.bill_total_txt, to be able to put text in it from the total function
self.bill_total_txt = Text(self,
height = 10,
width = 40,
wrap = WORD)
self.bill_total_txt.grid(row = 3,
column = 0,
columnspan = 2,
sticky = W)
#Create a Submit button
submit = Button(self,
text = "Submit",
command = self.total)
submit.grid(row = 4,
column = 0,
sticky = W)
def total(self):
""" Takes the values from Bill, and # of people to get the amount that will be
displayed in the text box."""
TAX = .15
## Try to convert the bill to a float and the number of people to an integer
try:
bill = float(self.billvar.get())
people = int(self.pplvar.get())
## If something goes wrong tell the user the input is invalid
except:
self.bill_total_txt.delete(0.0, END)
self.bill_total_txt.insert(0.0, 'Invalid input')
## If the conversion was possible, calculate the tip, the total amount and the amout per person and format them as a string with two decimals
## Then create the complete message as a list and join it togeather when writing it to the textbox
else:
tip = "%.2f" % (TAX * bill)
tot = "%.2f" % (TAX * bill + bill)
tot_pp = "%.2f" % ((TAX * bill + bill) / people)
Total = ["The tip is: $", tip,
"\nThe total for the bill is: $",
tot,
" divided among the people paying equally is: $",
tot_pp,
" per person."]
self.bill_total_txt.delete(0.0, END)
self.bill_total_txt.insert(0.0, ''.join(Total))
#Starting the Program
root = Tk()
root.title("Tip Calculator")
app = Calculator(root)
root.mainloop()
I wrote a simple program importing Tkinter just to play with Radio Buttons. I find that I'm getting errors in very, very weird places.
from Tkinter import *
class Application (Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
Label(self, text = "Select the last book you read.").grid (row = 0, column = 0, sticky = W)
self.choice = StringVar()
Radiobutton (self,text = "Nausea by Jean-Paul Sartre",variable = self.choice,
value = "Wake up. This is a dream. This is all only a test of the emergency broadcasting system.",
command = self.update_text).grid (row = 2, column = 1, sticky = W)
Radiobutton (self,
text = "Infinite Jest by David Foster Wallace",
variable = self.choice,
value = "Because an adult borne without the volition to choose the thoughts that he thinks, is going to get hosed ;)",
command = self.update_text).grid (row = 3, column = 1, sticky = W)
Radiobutton (self,
text = "Cat's Cradle by Kurt Vonnegut",
variable = self.choice,
value = " \"Here we are, trapped in the amber of the moment. There is no why!\" ",
command = self.update_text.grid (row = 4, column = 1, sticky = W)
self.txt_display = Text (self, width = 40, height = 5, wrap = WORD)
self.txt_display.grid (row = 6, column = 0, sticky = W)
#There is only one choice value - self.choice. That can be "printed."
def update_text(self):
message = self.choice.get()
self.txt_display.delete (0.0, END)
self.txt_display.insert (0.0, message)
# The Main
root = Tk()
root.title ("The Book Critic One")
root.geometry ("400x400")
app = Application (root)
root.mainloop()
I seem to be getting errors in very odd places. One came in the "=" sign in the Label attribution and when I changed it to == when i was playing around, the next one came in the variable part of the RadioButton attributes.
Any help would be greatly appreciated. Won't be able to respond immediately as I have to leave to work in a bit, but if you do spot where the bugs are, please let me know.
There are a lot of things going on here. I'll just point out the few that I've found quickly looking at this.
For your Label you shouldn't have = before your parameters...
Label = (self, text = "Select the last book you read.").grid (row = 0, column = 0, sticky = W)
to:
Label(self, text = "Select the last book you read.").grid (row = 0, column = 0, sticky = W)
Change all instances of RadioButton to Radiobutton as that is the actual name of the class in Tkinter.
choice1, choice2, and choice3 do not exist in Application.
More Stuff:
def create_widgets() is missing the self parameter: def create_widgets(self)
Your update_text() function isn't working because you're referencing self.text_display, I believe you want this to be self.txt_display since that is how you defined it previously.