set the correct Tkinter widgets position in Python -


i writing gui raw image converter in python using tkinter. gui divide in 3 part. part has button import raw file, part b has 4 checkbuttons, , part c has checkbuttons 2 entry spaces.

enter image description here

the length of columns 0 (= first) given label "correct chromatic aberration" (the longest element). mean if change name example in correct chromatic aberration white balance" elements shifted image below, , part a, b, , c related each other.

enter image description here

i wish make independent part part b, , on, in order have below image. in other words wish place each block of buttons own frame, , frames in main window.

enter image description here

the original code is:

from __future__ import division tkinter import * import tkmessagebox import tkfiledialog  class mainwindow(frame):     def __init__(self):         frame.__init__(self)         self.master.title("foo converter")         self.master.minsize(350, 150)         self.grid(sticky=e+w+n+s)          self.save_dir = none         self.filename_open = none          top = self.winfo_toplevel()         top.rowconfigure(0, weight=1)         top.columnconfigure(0, weight=1)          self.chart_file_types = [('pentax electronic format', '*.pef'),                                 ('sony alpha raw', '*.arw'),                                 ('minolta raw', '*.mrw'),                                 ('camera image file format', '*.crw'),                                 ('canon raw', '*.cr2'),                                 ('epson raw', '*.erw'),                                 ('samsung raw', '*.srw'),                                 ('fujifilm raw', '*.raf'),                                 ('kodak digital camera raw', '*.dcr'),                                 ('nikon electronic format', '*.nef'),                                 ('olympus raw', '*.orf'),                                 ('all files', '.*')]          in range(10): self.rowconfigure(i, weight=1)         self.columnconfigure(1, weight=1)          self.open = button(self, text='input raw image file', command=self.open, activeforeground="red")         self.open.grid(row=0, column=0, pady=2, padx=2, sticky=e+w+n+s)          self.sep = frame(self, height=2, width=450, bd=1, relief=sunken)         self.sep.grid(row=1, column=0, columnspan=4, padx=5, pady=5)          self.checkvar_camera_white_balance = intvar()         self.checkvar_camera_white_balance = checkbutton(self,             text="camera white balance",             variable=self.checkvar_camera_white_balance,             onvalue=1,             offvalue=0)         self.checkvar_camera_white_balance.grid(row=2, column=0, pady=0, padx=0, sticky=w)          self.checkvar_average_whole_image_white_balance = intvar()         self.checkvar_average_whole_image_white_balance = checkbutton(self,             text="average whole image white balance",             variable=self.checkvar_average_whole_image_white_balance,             onvalue=1,             offvalue=0)         self.checkvar_average_whole_image_white_balance.grid(row=3, column=0, pady=0, padx=0, sticky=w)          self.checkvar_correct_chromatic_aberration = intvar()         self.checkvar_correct_chromatic_aberration = checkbutton(self,             text="correct chromatic aberration",             variable=self.checkvar_correct_chromatic_aberration,             onvalue=1,             offvalue=0)         self.checkvar_correct_chromatic_aberration.grid(row=4, column=0, pady=0, padx=0, sticky=w)          self.checkvar_fix_dead_pixels = intvar()         self.checkvar_fix_dead_pixels = checkbutton(self,             text="fix dead pixels",             variable=self.checkvar_fix_dead_pixels,             onvalue=1,             offvalue=0)         self.checkvar_fix_dead_pixels.grid(row=5, column=0, pady=0, padx=0, sticky=w)          self.sep = frame(self, height=2, width=450, bd=1, relief=sunken)         self.sep.grid(row=6, column=0, columnspan=4, padx=5, pady=5)          self.checkvar_brightness = intvar()         self.checkvar_brightness = checkbutton(self, text="brightness",             command=self.switch_brightness,             variable=self.checkvar_brightness,             onvalue=1,             offvalue=0)         self.checkvar_brightness.grid(row=7, column=0, pady=0, padx=2, sticky=w)          self.label_level_brightness = label(self, text="brightness level:", state=disabled)         self.label_level_brightness.grid(row=8, column=0, pady=0, padx=0, sticky=w)          self.entry_level_brightness = entry(self, state=disabled)         self.entry_level_brightness.grid(row=8, column=1, pady=0, padx=0, sticky=w)          self.label_gamma_curve = label(self, text="gamma curve:", state=disabled)         self.label_gamma_curve.grid(row=9, column=0, pady=0, padx=0, sticky=w)          self.entry_gamma_curve_1 = entry(self, state=disabled)         self.entry_gamma_curve_1.grid(row=9, column=1, pady=0, padx=0, sticky=w)          self.entry_gamma_curve_2 = entry(self, state=disabled)         self.entry_gamma_curve_2.grid(row=9, column=2, pady=0, padx=0, sticky=e+w+n+s)   # functions      def open(self):         self.filename_open = tkfiledialog.askopenfilename(filetypes=self.chart_file_types, defaultextension='.*')      def switch_brightness(self):         pass  if __name__ == "__main__":    d = mainwindow()    d.mainloop() 

if want regions independent, use frame each region. example:

top_frame = frame(self, ...) middle_frame = frame(self, ...) bottom_frame = frame(self, ...)  top_frame.pack(side="top", fill="x") middle_frame.pack(side="top", fill="x") bottom_frame.pack(side="top", fill="x") 

with that, can treat each region independently. affords luxury of using different geometry managers different sections. may want use pack in top , middle frame, , grid in lower frame.

# top frame self.open = button(top_frame, ...) self.open.pack(side="left") ... # middle frame self.checkvar_camera_white_balance = checkbutton(middle_frame, ...) self.checkvar_camera_white_balance.pack(side="top", fill="x") ... # bottom frame self.checkvar_brightness = checkbutton(bottom_frame, ...) self.checkvar_brightness.grid(row=0, column=0, pady=0, padx=2, sticky=w) ... 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -