Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter loops
#4
See comments in the code below
import tkinter as tk  # dont flood name space with * imports


class Months():  # Capital M for class name
    def __init__(self, name, days_of_the_month, year):
        self.name = name  # self. not months.
        self.days = days_of_the_month  # self. not months.
        self.year = year  # self. not months.


root = tk.Tk()  # add tk.
january = Months('January', 31, 2020) # Capital M for class name
february = Months('February', 29, 2020) # Capital M for class name
december = Months('December', 31, 2020) # Capital M for class name

months_list = [january, february, december]

for item in months_list:  # iterate over the items directly
    new_LabelFrame = tk.LabelFrame(root, text=item.name)  # add tk., item.name
    new_LabelFrame.pack()
    new_label = tk.Label(new_LabelFrame, text='Name: {}\nDays: {}\nYear: {}'.format(
        item.name, item.days, item.year))  # add tk., item. name,days & year
    new_label.pack()

root.mainloop()
Reply


Messages In This Thread
Tkinter loops - by mattemio - Apr-12-2020, 07:36 AM
RE: Tkinter loops - by deanhystad - Apr-12-2020, 09:58 AM
RE: Tkinter loops - by mattemio - Apr-12-2020, 11:43 AM
RE: Tkinter loops - by Yoriz - Apr-12-2020, 12:04 PM
RE: Tkinter loops - by mattemio - Apr-12-2020, 12:33 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020