Peter Yun
Peter Yun

Reputation: 9

can somebody tell me why it is not working

I am kind of begginer of python and I tried to do the code below, but is not working. can somebody help me?

from tkinter import *

root = Tk()

root.title("Peter")
root.geometry("500x300")
Ez_System = LabelFrame(root,text = "Ez_System")
Ez_System.pack(fill="both", expand="yes")



class frame:
    def __init__(self,frame_name,color,text):
        self.frame_name = frame_name
        self.color = color
        self.text = text
        
     
        
    def body_frame(self):
        self.frame_name =f'LabelFrame(Ez_System,text = {self.text},bg={self.color})'
        self.frame_name.pack(side = "left",fill="both",expand="yes")
        
        
frame1 = frame("frame1","yellow","frame1")
frame1.body_frame()
frame2 = frame("frame2","blue","frame2")
frame2.body_frame()

root.mainloop()

----the error is that "AttributeError: 'str' object has no attribute 'pack'"

Upvotes: 0

Views: 43

Answers (1)

acw1668
acw1668

Reputation: 46669

I wonder where you learnt that you can use a f-string to create tkinter widget like below:

self.frame_name =f'LabelFrame(Ez_System,text = {self.text},bg={self.color})'

You can simply change it to:

self.frame_name = LabelFrame(Ez_System, text=self.text, bg=self.color)

Upvotes: 1

Related Questions