Home:ALL Converter>improve Frame of Tkinter in Python

improve Frame of Tkinter in Python

Ask Time:2015-08-26T07:04:52         Author:Gianni Spear

Json Formatter

I am quite new to use Frame of Tkinter in Python. I discovered Frame from the following post When i run the GUI the Check box are not in the same line.

enter image description here

For this reason i have the following two questions:

1) is it possible to use "grid" in the frame in order to place the widget where i wish?

2) Is it possible to place for example "Camera white balance" and "average white balance" in the same row? in grid is for example row=0, column=0 and row=0, column=1

3) if i add a line below the button "Input raw image file" using the code:

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)

The Run works forever without showing the GUI.

My code is:

from __future__ import division
from Tkinter import *
import tkMessageBox
import tkFileDialog


class MainWindow(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("FOO frame")
        self.master.minsize(350, 150)
        self.grid(sticky=W+N+S+E)

        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")

        self.open = Button(top_frame,text="Input raw image file",
                           command=self.open,
                           activeforeground="red")
        self.open.pack(side="left")

        self.CheckVar_camera_white_balance = IntVar()
        self.CheckVar_camera_white_balance = Checkbutton(middle_frame,
            text="Camera white balance",
            variable=self.CheckVar_camera_white_balance,
            onvalue=1,
            offvalue=0)
        self.CheckVar_camera_white_balance.pack(side="top", fill="x")

        self.CheckVar_average_whole_image_white_balance = IntVar()
        self.CheckVar_average_whole_image_white_balance = Checkbutton(middle_frame,
            text="Average white balance",
            variable=self.CheckVar_average_whole_image_white_balance,
            onvalue=1,
            offvalue=0)
        self.CheckVar_average_whole_image_white_balance.pack()

        self.CheckVar_correct_chromatic_aberration = IntVar()
        self.CheckVar_correct_chromatic_aberration = Checkbutton(middle_frame,
            text="Correct chromatic aberration",
            variable=self.CheckVar_correct_chromatic_aberration,
            onvalue=1,
            offvalue=0)
        self.CheckVar_correct_chromatic_aberration.pack()

        self.CheckVar_fix_dead_pixels = IntVar()
        self.CheckVar_fix_dead_pixels = Checkbutton(middle_frame,
            text="Fix dead pixels",
            variable=self.CheckVar_fix_dead_pixels,
            onvalue=1,
            offvalue=0)
        self.CheckVar_fix_dead_pixels.pack()


# functions

    def open(self):
        self.filename_open = tkFileDialog.askopenfilenames(defaultextension='.*')

if __name__ == "__main__":
   d = MainWindow()
   d.mainloop()

Author:Gianni Spear,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32215510/improve-frame-of-tkinter-in-python
VRage :

Answers to your Questions Bryan Oakley gave you. Here is some code so you can imagine what he is talking about:\n\nfrom __future__ import division\n\nfrom Tkinter import *\nimport tkFileDialog\nimport tkMessageBox\nfrom ttk import Separator\n\n\nclass MainWindow(Frame):\n def __init__(self):\n Frame.__init__(self)\n self.master.title(\"FOO frame\")\n self.master.minsize(350, 150)\n self.grid(sticky=W+N+S+E)\n\n top_frame = Frame(self)\n middle_frame = Frame(self)\n bottom_frame = Frame(self)\n\n top_frame.pack(side=\"top\", fill=\"x\")\n middle_frame.pack(side=\"top\", fill=\"x\")\n bottom_frame.pack(side=\"top\", fill=\"x\")\n\n self.open = Button(top_frame,text=\"Input raw image file\",\n command=self.open,\n activeforeground=\"red\")\n self.open.pack(side=\"left\")\n\n self.sep = Separator(middle_frame, orient=HORIZONTAL)\n self.sep.grid(row=0, column=0, columnspan=2, sticky=\"WE\", pady=5)\n\n self.CheckVar_camera_white_balance = IntVar()\n self.CheckVar_camera_white_balance = Checkbutton(middle_frame,\n text=\"Camera white balance\",\n variable=self.CheckVar_camera_white_balance,\n onvalue=1,\n offvalue=0)\n self.CheckVar_camera_white_balance.grid(row=1, column=0, sticky=\"W\")\n\n self.CheckVar_average_whole_image_white_balance = IntVar()\n self.CheckVar_average_whole_image_white_balance = Checkbutton(middle_frame,\n text=\"Average white balance\",\n variable=self.CheckVar_average_whole_image_white_balance,\n onvalue=1,\n offvalue=0)\n self.CheckVar_average_whole_image_white_balance.grid(row=1, column=1, sticky=\"W\")\n\n self.CheckVar_correct_chromatic_aberration = IntVar()\n self.CheckVar_correct_chromatic_aberration = Checkbutton(middle_frame,\n text=\"Correct chromatic aberration\",\n variable=self.CheckVar_correct_chromatic_aberration,\n onvalue=1,\n offvalue=0)\n self.CheckVar_correct_chromatic_aberration.grid(row=2, column=0, columnspan=2, sticky=\"W\")\n\n self.CheckVar_fix_dead_pixels = IntVar()\n self.CheckVar_fix_dead_pixels = Checkbutton(middle_frame,\n text=\"Fix dead pixels\",\n variable=self.CheckVar_fix_dead_pixels,\n onvalue=1,\n offvalue=0)\n self.CheckVar_fix_dead_pixels.grid(row=3, column=0, columnspan=2, sticky=\"W\")\n\n\n# functions\n\n def open(self):\n self.filename_open = tkFileDialog.askopenfilenames(defaultextension='.*')\n\nif __name__ == \"__main__\":\n d = MainWindow()\n d.mainloop()\n\n\nIf you separator you can use the Seperatorclass, i was adding the seperator to the middle_frame so you have more control of this widget. Now you can use column to set \"Camera white balance\" and \"average white balance\" side by side. The columnspan attribute defines the number of columns a widget should span. So if you have more than 2 columns update that attribute. Finally if you use sticky you can define on which side the widget should stay.",
2015-08-26T05:55:36
yy