python - Tkinter widget not filling grid -


i seem struggling grid in tkinter, new , have trawled forum , web not found answer.

i 2 buttons , label fill grid has fixed size of 320 x 240. had trouble sticky , having read net written in 3 different ways, none of them throw error none of them work.

here code:

import tkinter tk  class application(tk.frame):     def __init__(self, master=none):         self.setlounge = 21.0         tk.frame.__init__(self, master)         self.grid()         self.createwidgets()      def createwidgets(self):         self.lou_dec = tk.button(self)         self.lou_dec["text"] = "<"         self.lou_dec["command"] = self.loudec         self.lou_dec.grid(row=1, column=1, sticky=("n", "s", "e", "w"))          self.lblloutemp = tk.label(self)         self.lblloutemp["text"] = self.setlounge         self.lblloutemp.grid(row=1, column=2, sticky=(tk.n + tk.s + tk.e + tk.w))          self.lou_inc = tk.button(self)         self.lou_inc["text"] = ">"         self.lou_inc["command"] = self.louinc         self.lou_inc.grid(row=1, column=3, sticky=(tk.n, tk.s, tk.e, tk.w))      def loudec(self):         self.setlounge -= 0.5         print ("%s" % self.setlounge)         fo = open("/home/tony/code/tempreg.txt", "w")         fo.write("%s" % self.setlounge)         fo.close()      def louinc(self):         self.setlounge += 0.5         print ("%s" % self.setlounge)         fo = open("/home/tony/code/tempreg.txt", "w")         fo.write("%s" % self.setlounge)         fo.close()  root = tk.tk() root.title("heating controller") root.geometry("320x240") app = application(master=root) app.mainloop()` 

many thanks

looking @ this post, seems it's necessary supply weight argument rowconfigure , columnconfigure if want widget stretch fit environment. in case, have twice - once widgets in frame, , once frame itself. don't forget make frame sticky, too.

import tkinter tk  class application(tk.frame):     def __init__(self, master=none):         self.setlounge = 21.0         tk.frame.__init__(self, master)         master.columnconfigure(0, weight=1)         master.rowconfigure(0, weight=1)         self.grid(sticky="news")         self.createwidgets()      def createwidgets(self):         self.lou_dec = tk.button(self)         self.lou_dec["text"] = "<"         self.lou_dec["command"] = self.loudec         self.lou_dec.grid(row=1, column=1, sticky=("n", "s", "e", "w"))          self.lblloutemp = tk.label(self)         self.lblloutemp["text"] = self.setlounge         self.lblloutemp.grid(row=1, column=2, sticky=(tk.n + tk.s + tk.e + tk.w))          self.lou_inc = tk.button(self)         self.lou_inc["text"] = ">"         self.lou_inc["command"] = self.louinc         self.lou_inc.grid(row=1, column=3, sticky=(tk.n, tk.s, tk.e, tk.w))          in range(1,4):             self.columnconfigure(i, weight=1)         self.rowconfigure(1, weight=1)      def loudec(self):         self.setlounge -= 0.5         print ("%s" % self.setlounge)         fo = open("/home/tony/code/tempreg.txt", "w")         fo.write("%s" % self.setlounge)         fo.close()      def louinc(self):         self.setlounge += 0.5         print ("%s" % self.setlounge)         fo = open("/home/tony/code/tempreg.txt", "w")         fo.write("%s" % self.setlounge)         fo.close()  root = tk.tk() root.title("heating controller") root.geometry("320x240") app = application(master=root) app.mainloop() 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -