Reputation: 131
the problem is realy simple, all funcions .packs(fill=X) for some reason don't work and in other hand if I use .pack(fill=X,pady=10) only pady works and fill=X is ignored. I hope that someone can explain to me why this is happing.
from tkinter import *
import json
import time
#opens file where pinger saves information about websites
def openfile():
d={}
with open('test.json', 'r') as f:
for line in f:
line_ = json.loads(line)
name = list(line_.keys())[0]
status = list(line_[name].keys())[0]
ip = line_[name][status]
d[name] = {'name':name, 'status':status, 'ip':ip}
f.close()
return d
#GUI main class
class GUI(Tk):
def __init__(self):
self.tk = Tk()
self.tk.configure(background='white')
self.tk.wm_state('zoomed')
self.label = {}
self.topFrame = Frame(self.tk, bg="white")
self.tk.after(5000, self.task)
self.title = Frame(self.tk, bg="white")
self.title.pack (side=TOP)
#self.topFrame.pack(side=TOP, expand=True)
self.topFrame.pack(side=TOP)
self.titlelbl= Label(self.title, text="Website Status: Green - Online, Red - Offline \n",bg="white", font=("Helvetica", 24))
self.titlelbl.pack(fill=X,pady=10)
#Funcion which creates and updates frame
def task(self):
i = 0
list={}
list = openfile()
if self.label != {}:#deleting previous information that we could refresh
for ele in self.label:
self.label[ele].destroy()
self.label= {}
for elem in list:#creating visual status if server is online text is in color green and opsite red
if list[elem]["status"]=="true":
lb = Label(self.topFrame, text=list[elem]["name"], fg="green",bg="white", font=("Helvetica", 24))
if list[elem]["status"]=="false":
lb = Label(self.topFrame, text=list[elem]["name"], fg="red",bg="yellow", font=("Helvetica", 24))
lb.pack(fill=X,pady=10)
self.label[elem] = lb
self.tk.after(5000, self.task)#Program refresh main window works every 5s
#forever loop
Gui= GUI()
Gui.mainloop()
Upvotes: 0
Views: 1185
Reputation: 11635
You never expand / fill the frame widget, so the frame is only as large as necessary for it to hold all of it's children.
The padding options will increase the size (padding) of the children, and you'll be able to see the difference. Whereas with fill
there's nothing for the child widget to fill it's already taking up as much space as it can in it's master (self.topFrame
)
Upvotes: 1