Grid_forget() doesn't seem to forget widgets - python

I have a problem regarding tkinter's grid_forget() method. I have 2 pages in a notebook and I want to show certain widgets on the second page based off the user's selected options in the first page, I have a multiple choice menu and the grid_forget() method seems to work well until I select 2 or more options from the menu. I tried creating the widgets when an option is selected and place them based on the choice, no luck there, also tried creating them with the rest of the widgets and when the user selected an option I would simply just use grid to place them on the screen, also no luck there. I created a demo below, sorry for potential mistakes.
import tkinter as tk
from tkinter import ttk
SMALL_FONT = ("calibri", 16)
class App(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.notebook = ttk.Notebook(self, height = "900", width = "1600")
self.notebook.grid(row = 0, column = 0)
self.frame_pasul3 = tk.Frame(self.notebook)
self.frame_pasul1 = tk.Frame(self.notebook)
self.notebook.add(self.frame_pasul1, text = "First page")
self.notebook.add(self.frame_pasul3, text = "Second page")
self.first_page()
def first_page(self):
options = ["Urmarire mobiliara",
"Urmarire imobiliara",
"Predarea silita bunuri imobile",
"Predarea silita bunuri mobile",
"Obligatia de a face",
"Executare minori"]
menubutton_modalitate_exec = tk.Menubutton(self.frame_pasul1, text="Alegeti o modalitate de executare",
indicatoron=True, borderwidth=1, fg = "#000000",relief="raised")
menu_modalitate_exec = tk.Menu(menubutton_modalitate_exec, tearoff=False)
menubutton_modalitate_exec.configure(menu=menu_modalitate_exec)
menubutton_modalitate_exec.grid(row = 4, column = 1)
self.modalitate = {}
for choice in options:
self.modalitate[choice] = tk.StringVar()
menu_modalitate_exec.add_checkbutton(label=choice, variable=self.modalitate[choice],
onvalue=1, offvalue=0,
command=self.printValues)
self.second_page()
def second_page(self):
self.frame3_titlu_exec = ttk.Frame(self.frame_pasul3)
self.frame3_titlu_exec.grid()
self.frame3_text = ttk.Frame(self.frame_pasul3)
self.frame3_text.grid()
self.frame3_creante = tk.Frame(self.frame_pasul3)
self.frame3_creante.grid()
self.frame3_reprezentand_obligatia = tk.Frame(self.frame_pasul3)
self.frame3_judecatorie = ttk.Frame(self.frame_pasul3)
self.frame3_judecatorie.grid()
self.frame3_texte = tk.Frame(self.frame_pasul3)
self.frame3_texte.grid()
ttk.Label(self.frame3_titlu_exec, font = SMALL_FONT, text = "Titlu Executoriu").grid(row = 0, column = 0, columnspan = 4 ,pady = 10)
ttk.Button(self.frame3_titlu_exec, text = "Contract de credit.").grid(row = 1, column = 0, padx = 10, ipadx = 15, ipady = 5)
ttk.Button(self.frame3_titlu_exec, text = "Sentinta civila.").grid(row = 1, column = 1, padx = 10, ipadx = 15, ipady = 5)
ttk.Button(self.frame3_titlu_exec, text = "Contract notarial.").grid(row = 1, column = 2,padx = 10, ipadx = 15, ipady = 5)
ttk.Button(self.frame3_titlu_exec, text = "Act de adjudecare.").grid(row = 1, column = 3, padx = 10, ipadx = 15, ipady = 5)
self.entry = tk.Text(self.frame3_text, height = 2, wrap = "word", font = ("Helvetica", 10))
self.entry.grid(row = 0, column = 1, padx = 10, pady = 15)
ttk.Button(self.frame3_text, text = "Incarca titlu").grid(row = 0, column = 2, padx = 10, pady = 15)
ttk.Label(self.frame3_creante, font = SMALL_FONT, text = "Creante").grid(row = 0, column = 0)
self.btn_adauga_creante = ttk.Button(self.frame3_creante, text = "Adauga")
self.btn_adauga_creante.grid(row = 0, column = 3)
self.reprezentand_fapt_label = ttk.Label(self.frame3_judecatorie, font = SMALL_FONT, text = "Ce reprezinta fapta.")
self.reprezentand_fapt_label.grid(row = 2, column = 1)
self.reprezentand_creante = tk.Text(self.frame3_judecatorie, height = 3, width = 70)
self.reprezentand_creante.grid(row = 3 , column = 1, pady = 15)
ttk.Label(self.frame3_texte, font = SMALL_FONT, text = "Judecatorie").grid(row = 4, column = 1)
options_jud = ["optiunea 2.",
"test 3",
"test 4",
"test 5"]
self.judecatorie = ttk.Combobox(self.frame3_texte, values = options_jud)
self.judecatorie.set("Selecteaza o judecatorie.")
self.judecatorie.grid(row = 5, column = 1)
ttk.Button(self.frame3_texte, text = "Pasul 2. Parti dosar.").grid(row = 6, column = 0, padx = 15, ipadx = 15, ipady = 5)
ttk.Button(self.frame3_texte, text = "Pasul 4. Cheltuieli de executare").grid(row = 6, column = 3, ipadx = 15, ipady = 5)
def printValues(self):
for name, var in self.modalitate.items():
if var.get() == "1" and (name == "Predarea silita bunuri imobile" or name == "Predarea silita bunuri mobile" or name == "Obligatia de a face" or name == "Executare minori"):
self.reprezentand_creante_label = tk.Label(self.frame3_judecatorie, font = SMALL_FONT, text = "Ce reprezinta creanta.")
self.reprezentand_creante = tk.Text(self.frame3_judecatorie, wrap = "word", height = 3, width = 70)
self.ok_modalitate_exec = 1
self.reprezentand_creante_label.grid(row = 0, column = 1, padx = 15, pady = 15)
self.reprezentand_creante.grid(row = 1, column = 1, padx = 15, pady = 15)
print("Avem 1 la cele 4", name, var.get())
break
elif var.get() == "0" and (name == "Predarea silita bunuri imobile" or name == "Predarea silita bunuri mobile" or name == "Obligatia de a face" or name == "Executare minori"):
print("Avem 0 la cele 4", name, var.get())
self.ok_modalitate_exec = 0
self.reprezentand_creante_label.grid_forget()
self.reprezentand_creante.grid_forget()
break
if __name__ == "__main__":
main_window = tk.Tk()
app = App(main_window)
app.grid()
main_window.mainloop()

Related

Cannot access variables of an object - 'has no attribute'

Why can I not access any variables that I create in this class? I get Control has no attribute setTemp whenever I try to access it. If I declare it outside __init__ I also get an error. For whatever reason, I can't grasp how to properly declare variables in a Python class, then later use them in methods.
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from vivTimer import *
import RPi.GPIO as GPO
import threading
import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT22(board.D4, use_pulseio=False)
class Control(object):
setHumid = 95
timer = 5000
def __init__(self, master):
setTemp = StringVar()
setTemp.set('85')
#set default max temp and humidity
master.title('Vivarium Control')
master.resizable(False, False)
master.configure(background = '#e6e6e6')
self.style = ttk.Style()
self.style.configure('TFrame', background = '#e6e6e6')
self.style.configure('TButton', background = '#e1d8b9')
self.style.configure('TLabel', background = '#e6e6e6', font = ('Arial', 11))
self.style.configure('Header.TLabel', font = ('Arial', 18, 'bold'))
self.frame_header = ttk.Frame(master)
self.frame_header.pack()
self.logo = PhotoImage(file = '115500-200.png')
ttk.Label(self.frame_header, image = self.logo).grid(row = 0, column = 0, rowspan = 2)
ttk.Label(self.frame_header, text = 'Vivarium Controller', style = 'Header.TLabel').grid(row = 0, column = 1)
ttk.Label(self.frame_header, wraplength = 300,
text = ("Temperature and Humidity control. "
"Enter maximums for both humidity and temperature.")).grid(row = 1, column = 1, padx = 5, sticky = 'nw')
self.frame_content = ttk.Frame(master)
self.frame_content.pack()
ttk.Label(self.frame_content, text = 'Maximum Temp:').grid(row = 0, column = 0, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Maximum Humidity:').grid(row = 0, column = 1, padx = 5, sticky = 'sw')
self.setTempL = Label(self.frame_content, textvariable = setTemp).grid(row = 0, column = 3, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Current Humidity:' + str(self.setHumid)).grid(row = 0, column = 4, padx = 5, sticky = 'sw')
self.entry_temp = ttk.Entry(self.frame_content, textvariable = setTemp, width = 10, font = ('Arial', 10))
self.entry_humid = ttk.Entry(self.frame_content, width = 10, font = ('Arial', 10))
self.entry_temp.grid(row = 1, column = 0, padx = 5)
self.entry_humid.grid(row = 1, column = 1, padx = 5)
ttk.Button(self.frame_content, text = 'Save',
command = self.save).grid(row = 4, column = 0, padx = 5, pady = 5, sticky = 'e')
def updateLabels(self):
print('blah')
def createTimer(root):
print('timer 1 sec')
readTemp = False
while readTemp == False:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)
readTemp = True
if(temperature_f > int(Control.setTemp.get())):
print('fan on')
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
time.sleep(2.0)
print(Control.timer)
root.after(Control.timer, Control.createTimer, root)
#t2 = threading.Thread(target=VivTimer.startTimer(), args=(10,))
#t2.start()
def save(self):
tempT = self.entry_temp.get()
self.setTemp = tempT
print(self.setTemp)
self.setHumid = self.entry_humid.get()
Control.updateLabels(self)
print('Temp: {}'.format(self.entry_temp.get()))
print('Humidity: {}'.format(self.entry_humid.get()))
self.clear()
messagebox.showinfo(title = 'Vivarium Control', message = 'Conditions saved!')
def clear(self):
self.entry_temp.delete(0, 'end')
self.entry_humid.delete(0, 'end')
def main():
root = Tk()
control = Control(root)
root.after(1000, Control.createTimer, root)
root.mainloop()
if __name__ == "__main__": main()
I think the following modified version of your code will work much better if you undo all the places I commented out your code (and usually put in a replacement below it). This was necessary to make it possible to run the code at all for testing since I don't have your hardware (or the one image file).
You will need to undo them to try it with your hardware.
The two most significant changes I made were turning setTemp into a class instance attribute and modifying createTimer() to make it a proper class method.
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
#from vivTimer import *
#import RPi.GPIO as GPO
import time
#import board
#import adafruit_dht
#
#dhtDevice = adafruit_dht.DHT22(board.D4, use_pulseio=False)
class Control(object):
setHumid = 95
timer = 5000
def __init__(self, master):
self.setTemp = StringVar()
self.setTemp.set('85')
#set default max temp and humidity
master.title('Vivarium Control')
master.resizable(False, False)
master.configure(background = '#e6e6e6')
self.style = ttk.Style()
self.style.configure('TFrame', background = '#e6e6e6')
self.style.configure('TButton', background = '#e1d8b9')
self.style.configure('TLabel', background = '#e6e6e6', font = ('Arial', 11))
self.style.configure('Header.TLabel', font = ('Arial', 18, 'bold'))
self.frame_header = ttk.Frame(master)
self.frame_header.pack()
# self.logo = PhotoImage(file = '115500-200.png')
self.logo = PhotoImage(file = '8-ball.png')
ttk.Label(self.frame_header, image = self.logo).grid(row = 0, column = 0, rowspan = 2)
ttk.Label(self.frame_header, text = 'Vivarium Controller', style = 'Header.TLabel').grid(row = 0, column = 1)
ttk.Label(self.frame_header, wraplength = 300,
text = ("Temperature and Humidity control. "
"Enter maximums for both humidity and temperature.")).grid(row = 1, column = 1, padx = 5, sticky = 'nw')
self.frame_content = ttk.Frame(master)
self.frame_content.pack()
ttk.Label(self.frame_content, text = 'Maximum Temp:').grid(row = 0, column = 0, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Maximum Humidity:').grid(row = 0, column = 1, padx = 5, sticky = 'sw')
self.setTempL = Label(self.frame_content, textvariable=self.setTemp).grid(row = 0, column = 3, padx = 5, sticky = 'sw')
ttk.Label(self.frame_content, text = 'Current Humidity:' + str(self.setHumid)).grid(row = 0, column = 4, padx = 5, sticky = 'sw')
self.entry_temp = ttk.Entry(self.frame_content, textvariable=self.setTemp, width = 10, font = ('Arial', 10))
self.entry_humid = ttk.Entry(self.frame_content, width = 10, font = ('Arial', 10))
self.entry_temp.grid(row = 1, column = 0, padx = 5)
self.entry_humid.grid(row = 1, column = 1, padx = 5)
ttk.Button(self.frame_content, text = 'Save',
command = self.save).grid(row = 4, column = 0, padx = 5, pady = 5, sticky = 'e')
def updateLabels(self):
print('blah')
def createTimer(self, root):
print('timer 1 sec')
readTemp = False
while readTemp == False:
try:
# Print the values to the serial port
# temperature_c = dhtDevice.temperature
temperature_c = 30
temperature_f = temperature_c * (9 / 5) + 32
# humidity = dhtDevice.humidity
humidity = 20
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)
readTemp = True
if(temperature_f > int(self.setTemp.get())):
print('fan on')
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
# dhtDevice.exit()
raise error
time.sleep(2.0)
print(Control.timer)
root.after(Control.timer, self.createTimer, root)
def save(self):
tempT = self.entry_temp.get()
self.setTemp = tempT
print(self.setTemp)
self.setHumid = self.entry_humid.get()
Control.updateLabels(self)
print('Temp: {}'.format(self.entry_temp.get()))
print('Humidity: {}'.format(self.entry_humid.get()))
self.clear()
messagebox.showinfo(title = 'Vivarium Control', message = 'Conditions saved!')
def clear(self):
self.entry_temp.delete(0, 'end')
self.entry_humid.delete(0, 'end')
def main():
root = Tk()
control = Control(root)
root.after(1000, control.createTimer, root)
root.mainloop()
if __name__ == "__main__":
main()

OOP in Tkinter - Create Frame with Listbox

Hey I would like to create a frame which contains a Listbox and some buttons. What I would like to do is to somehow pass as an argument a name of this listbox. This is my current code in which I set the name of this listbox to master.thisListbox but I would like to pass it somehow as argument. Is it possible or should I separately crate a listbox in my App and the pass it as an argument to a frame? I'm going to create a lot of such listboxes in my App hence the name of listbox shouldn't be the same. I'm pretty new in OOP.
class myApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.dateFrame = DateFrame(self)
self.dateFrame.grid(row = 0, column = 0)
print(self.day.get())
self.myFrame = ListboxFrame(self, "Label!", [1,2,3])
self.myFrame.grid(row = 1, column = 0)
x = self.thisListbox.get(0, END)
print(x)
class DateFrame(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
# Day
ttk.Label(self, text = "Day", width = 4).grid(row = 0, column = 0, padx = 3, pady = 3)
master.day = IntVar(master, value = 31)
self.dayCB = ttk.Combobox(self, values = [x for x in range(1, 32)], textvariable = master.day, width = 4)
self.dayCB.grid(row = 1, column = 0, padx = 3, pady = 3)
# Month
ttk.Label(self, text = "Month", width = 6).grid(row = 0, column = 1, padx = 3, pady = 3)
self.month = IntVar(master, value = 12)
self.monthCB = ttk.Combobox(self, values = [x for x in range(1, 13)], textvariable = self.month, width = 4)
self.monthCB.grid(row = 1, column = 1, padx = 3, pady = 3)
# Year
ttk.Label(self, text = "Year", width = 4).grid(row = 0, column = 2, padx = 3, pady = 3)
self.year = IntVar(master, value = 2021)
self.yearCB = ttk.Spinbox(self, from_ = 2020, to = 2100, textvariable = self.year, width = 6)
self.yearCB.grid(row = 1, column = 2, padx = 3, pady = 3)
class ListboxFrame(ttk.Frame):
def __init__(self, master, labelText, values, selectmode = "extended", height = 6, width = 30):
ttk.Frame.__init__(self, master)
# Listbox
ttk.Label(self, text = labelText).grid(row = 0, column = 0, columnspan = 3)
master.thisListbox = tk.Listbox(self, selectmode = selectmode, height = height, width = width)
master.thisListbox.grid(row = 1, column = 0, columnspan = 3, padx = 2, pady = 2)
# Entry
self.entry = ttk.Entry(self)
self.entry.grid(row = 2, column = 0, padx = 2, pady = 2)
# Buttons
self.addButton = ttk.Button(self, text = "Add", width = 4, command = self.Add)
self.addButton.grid(row = 2, column = 1, padx = 2, pady = 2)
self.deleteButton = ttk.Button(self, text = "Delete", width = 6, command = self.Delete)
self.deleteButton.grid(row = 2, column = 2, padx = 2, pady = 2)
for v in values:
master.thisListbox.insert(END, v)
def Add(self):
if self.entry.get() == "": return
master.thisListbox.insert(END, self.entry.get())
self.entry.delete(0, END)
def Delete(self):
for index in reversed(master.thisListbox.curselection()):
master.thisListbox.delete(index)
# listbox.config(height = listbox.size())

Tkinter Get Value and then Destroy

I'm trying to create an app that has 2 windows. The first window (A) is only called the first time the app is ran, and then opens window (B). For all future events, only window (B) is called. This is the following code:
# Script Counter/Setup
def read_counter():
if path.exists("counter.json"):
return loads(open("counter.json", "r").read()) + 1
else:
info = tk.Tk()
info.title("Setup")
info.geometry("350x120")
info.grid_columnconfigure((0, 2), weight = 1)
count = tk.Label(info, text = "Previous Post Number")
string = tk.StringVar()
count_input = tk.Entry(info, textvariable = string)
val = string.get()
def destroy_get():
val = int(count_input.get())
info.quit()
return val
count_button = tk.Button(info, text = "Done!", command = destroy_get)
tk.Label(info, text = "Setup", font='Helvetica 18 bold').grid(row = 0, column = 1, padx = 5, pady = 5)
count.grid(row = 1, column = 0, padx = 5, pady = 5)
count_input.grid(row = 1, column = 2, padx = 5, pady = 5)
count_button.grid(row = 2, column = 1, padx = 5, pady = 5)
info.mainloop()
# info.destroy()
return destroy_get()
def write_counter():
with open("counter.json", "w") as f:
f.write(dumps(counter))
counter = read_counter()
atexit.register(write_counter)
folders = ["to_post/", "not_posted/", "posted"]
for folder in folders:
if not path.exists(folder):
os.mkdir(folder)
print(os.getcwd())
# GUI
window = tk.Tk()
window.title("Confessions Bot")
window.geometry("600x350")
window.grid_columnconfigure((0,2), weight = 1)
label_tell_account = tk.Label(window, text = "Tellonym Account")
label_tell_password = tk.Label(window, text = "Tellonym Password")
label_ig_account = tk.Label(window, text = "Instagram Account")
label_ig_password = tk.Label(window, text = "Instagram Password")
tell_account = tk.Entry(window)
tell_password = tk.Entry(window)
ig_account = tk.Entry(window)
ig_password = tk.Entry(window)
image = ImageTk.PhotoImage(Image.open("logo.png"))
tk.Label(window, image = image).grid(row = 0, column = 1, padx = 10, pady = 10)
label_tell_account.grid(row = 1, column = 0)
tell_account.grid(row = 1, column = 2, padx = 10, pady = 10)
label_tell_password.grid(row = 2, column = 0, padx = 10, pady = 10)
tell_password.grid(row = 2, column = 2, padx = 10, pady = 10)
label_ig_account.grid(row = 3, column = 0, padx = 10, pady = 10)
ig_account.grid(row = 3, column = 2, padx = 10, pady = 10)
label_ig_password.grid(row = 4, column = 0, padx = 10, pady = 10)
ig_password.grid(row = 4, column = 2, padx = 10, pady = 10)
# run.grid(row = 5, column = 1, padx = 10, pady = 10)
window.mainloop()
When this is ran I get _tkinter.TclError: image "pyimage1" doesn't exist. I read that this happens since I haven't destroyed my initial window. If I change destroy_get() to have info.destroy() I'm no longer able to get the the entry from window A.
This is my first time using Tkinter and coding in general so any help is welcome.

I can't get entry data in python 3.6

I made small medical calculator program for python learning.
In this program, when i press "Calc" button, it should be displayed in my command line. But it doesn't work.
Moreover, I suspect that the defined function is operated without button click.
What do i have a mistake?
#importing modules
from tkinter import *
#setting up window
top = Tk()
F = Frame(top)
F.master.title("FeNa Calculator")
F.pack()
#Calc. button event handler
def fena_click():
ur_na = tUNa.get()
ur_cr = tUCr.get()
se_na = tSNa.get()
se_cr = tSCr.get()
print('Urine Na : ' + ur_na, end=' ')
print('Urine Cr : ' + ur_cr, end=' ')
print('Serum Na : ' + se_na, end=' ')
print('Serum Cr : ' + se_cr, end=' ')
#add widgets
unit1 = Label(F, text="mEq/L")
unit2 = Label(F, text="mEq/L")
unit3 = Label(F, text="mEq/L")
unit4 = Label(F, text="mEq/L")
UNa = Label(F, text="Urine Na")
tUNa = Entry(F)
UCr = Label(F, text="Urine Cr")
tUCr = Entry(F)
SNa = Label(F, text="Serum Na")
tSNa = Entry(F)
SCr = Label(F, text="Serum Cr")
tSCr = Entry(F)
blank1 = Label(F, text="")
v_Result = StringVar()
Result = Label(F, textvariable = v_Result)
v_Result.set("FENa(%) = ")
blank2 = Label(F, text="")
bCalc = Button(F, text="Calc.", command = fena_click())
bQuit = Button(F, text="Quit", command = F.quit)
UNa.grid(row = 0, column = 0, pady = 2)
tUNa.grid(row =0, column = 1, pady = 2)
unit1.grid(row = 0, column = 2, pady = 2)
UCr.grid(row = 1, column = 0, pady = 2)
tUCr.grid(row =1, column = 1, pady = 2)
unit2.grid(row = 1, column = 2, pady = 2)
SNa.grid(row = 2, column = 0, pady = 2)
tSNa.grid(row =2, column = 1, pady = 2)
unit3.grid(row = 2, column = 2, pady = 2)
SCr.grid(row = 3, column = 0, pady = 2)
tSCr.grid(row =3, column = 1, pady = 2)
unit4.grid(row = 3, column = 2, pady = 2)
blank1.grid(row=4, column = 0, columnspan = 3)
Result.grid(row = 5, column = 0, columnspan = 3)
blank2.grid(row=6, column = 0, columnspan = 3)
bCalc.grid(row = 7, column = 0, columnspan = 2)
bQuit.grid(row = 7, column = 1, columnspan = 2)
#loop running
F.mainloop()
Program view
In the line where you're making the button, you are actually calling the fena_click function. You need to pass the function itself, which you can do by omitting the paranthesis:
bCalc = Button(F, text="Calc.", command = fena_click) # no () after fena_click

Tkinter button not working (Python 3.x)

I'm working on my final project for my computing I class.
The problem that I am having is:
When I click on the new entry button, hit the back button and click on the new entry button once again it does not work.
If you guys could tell me why that is?
The command on the button seems to be only working once. Thanks for your help.
Code:
from tkinter import *
import tkinter.filedialog
class App(Tk):
def __init__(self):
Tk.__init__(self)
self.title("Entry Sheet")
self.font = ("Helvetica","13")
self.header_font = ("Helvetica","18")
self.exercise_font = ("Helvetica","13","bold")
self.delete = 'a'
self.new_user()
def new_user(self):
if self.delete == 'b':
self.delete = 'c'
self.hide()
self.delete = 'b'
self.new_entry = Button(self, text = 'New Entry', command = self.entry, width = 15)
self.new_entry.grid(row = 1, column = 0, columnspan = 3, padx = 10, pady = 5)
self.look_entry = Button(self, text = 'See Entries', command = self.see_entries, width = 15)
self.look_entry.grid(row = 2, column =0, columnspan = 3, padx = 10, pady = 5)
def entry(self):
print(1)
self.delete = 'b'
self.hide()
self.entry = Label(self, text = 'New Entry', font = self.header_font)
self.entry.grid(row = 0, column = 0, columnspan = 2)
self.numberlbl = Label(self, text = 'Please choose a muscle?', font = self.font)
self.numberlbl.grid(row = 1, column= 0, columnspan = 2, sticky = 'w' )
self.muscle_chosen = IntVar()
self.chest = Radiobutton(self, text = "chest", variable = self.muscle_chosen, value = 1, font = self.font)
self.bicep = Radiobutton(self, text = "bicep", variable = self.muscle_chosen, value = 2, font = self.font)
self.chest.grid(row = 2, column = 0)
self.bicep.grid(row = 2, column = 1)
self.exerciseslbl = Label(self, text = 'Please enter the number of exercises: ', font = self.font)
self.exerciseslbl.grid(row = 3, column = 0, columnspan = 3)
self.exercises_spinbox = Spinbox(self, from_= 1, to_= 50, width = 5, font = self.font)
self.exercises_spinbox.grid(row = 4, column = 0)
self.back_button = Button(self, text = 'Back', command = self.new_user, width = 10)
self.back_button.grid(row =5, column=0, pady =10)
def see_entries(self):
print("Goes through")
def hide(self):
if self.delete == 'b':
self.new_entry.grid_remove()
self.look_entry.grid_remove()
elif self.delete == 'c':
self.entry.grid_remove()
self.numberlbl.grid_remove()
self.chest.grid_remove()
self.bicep.grid_remove()
self.exerciseslbl.grid_remove()
self.exercises_spinbox.grid_remove()
self.back_button.grid_remove()
def main():
app = App()
app.mainloop()
if __name__=="__main__":
main()
In your entry function you overwrite self.entry, which is the name of the function, with a reference to a Label. When the button then calls self.entry it isn't function.
Simply call the Label something else.

Categories

Resources