Reputation: 47
Hi this Adorable Trooper.
Currently, typing a basic recurring deposit calculator.
I have already wrote some code regarding the basic tabs layout for it.
I have also made a new tab, but the data which I want it to be displayed on it, seems to be in error.
from tkinter import *
root = Tk()
root.geometry("400x200")
root.title("Recurrinng deposit calculator.")
img = PhotoImage(file="Adorable trooper logo.png")
root.iconphoto(False, img)
# Creating a label to show The Title of the program.
TITLE = Label(root, text= "Recurring Deposits Calculator.", bg= "red", padx= 1000)
TITLE.pack()
# Definning functions for the RADIO BUTTON.
def display_intro():
root1 = Toplevel(root)
root1.title("Intro about Recurring deposits Calculator.")
info_frame = LabelFrame(root1, text="Intro about Recurring Deposits Calculator.")
info_frame.pack(fill="both", expand="yes")
info = Label(LabelFrame, text= "This is basically a basic calculator")
info.pack()
root1.mainloop()
var = IntVar()
# Displaying some Radio Buttons related to their command.
introduction_button = Radiobutton(root, text= "Introduction", command= display_intro, variable=var, value= 1)
introduction_button.pack(anchor = W)
root.mainloop()
This is the error.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ONE\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "c:/Users/ONE/Desktop/First Program/Basic Program/recurring interest.py", line 29, in display_intro
info = Label(LabelFrame, text= "This is basically a basic calculator")
File "C:\Users\ONE\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3143, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\ONE\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2561, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Users\ONE\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2530, in _setup
self.tk = master.tk
AttributeError: type object 'LabelFrame' has no attribute 'tk'
PS C:\Users\ONE\Desktop\First Program>
If anyone finds it's solution or maybe guiding me on this error, please reply as soon as possible.
Upvotes: 1
Views: 97
Reputation: 2270
Instead of making the parent widget of the widget info
the LabelFrame
, which is a class, you should make it info_frame
. This way, it will go inside the LabelFrame
. You can't pass a method as a parent in tkinter.
So, the full code:
from tkinter import *
root = Tk()
root.geometry("400x200")
root.title("Recurrinng deposit calculator.")
img = PhotoImage(file="yes.png")
root.iconphoto(False, img)
# Creating a label to show The Title of the program.
TITLE = Label(root, text= "Recurring Deposits Calculator.", bg= "red", padx= 1000)
TITLE.pack()
# Definning functions for the RADIO BUTTON.
def display_intro():
root1 = Toplevel(root)
root1.title("Intro about Recurring deposits Calculator.")
info_frame = LabelFrame(root1, text="Intro about Recurring Deposits Calculator.")
info_frame.pack(fill="both", expand="yes")
info = Label(info_frame, text= "This is basically a basic calculator")
info.pack()
root1.mainloop()
var = IntVar()
# Displaying some Radio Buttons related to their command.
introduction_button = Radiobutton(root, text= "Introduction", command= display_intro, variable=var, value= 1)
introduction_button.pack(anchor = W)
root.mainloop()
Output:
Upvotes: 4