N
newbie
Hello,
I am a newbie and have a few questions about Python and Tkinter.
I would like to create the following layout in Python:
*******************************************
* *
* *
* *
* frame 1 *
* *
* *
* *
* *
*******************************************
* * *
* * *
* * *
* frame 3 * frame 2 *
* * *
* * *
* * *
*******************************************
I try to accomplish this with the following code:
from Tkinter import *
root = Tk()
root.title("Critter World")
MyFrame0 = Frame(root, background="brown") # One Parent Frame to rule
them all
MyFrame1 = Frame(MyFrame0, background = "yellow")
MyFrame2 = Frame(MyFrame0, background = "red")
MyFrame3 = Frame(MyFrame0, background = "green")
b1 = Label(MyFrame1, text="World", background="yellow").pack(fill=BOTH,
expand=YES)
b2 = Label(MyFrame2, text="Info", background="red").pack(fill=BOTH,
expand=YES)
b3 = Label(MyFrame3, text="Control",
background="green").pack(fill=BOTH, expand=YES)
MyFrame1.pack(side=TOP, fill=BOTH, expand=YES)
MyFrame2.pack(side=RIGHT, fill=BOTH, expand=YES)
MyFrame3.pack(side=LEFT, fill=BOTH, expand=YES)
MyFrame0.pack(fill=BOTH, expand=YES)
raw_input()
print "\n"*23
When the window resizes, it is only Frame1 that is resized.
However, if I run the following:
from Tkinter import *
root = Tk()
root.title("Critter World")
MyFrame0 = Frame(root, background="brown") # One Parent Frame to rule
them all
MyFrame1 = Frame(MyFrame0, background="yellow")
MyFrame2 = Frame(MyFrame0, background = "red")
MyFrame3 = Frame(MyFrame0, background = "green")
MyFrame4 = Frame(MyFrame0, background = "black")
b1 = Label(MyFrame1, text="World", background="yellow").pack(fill=BOTH,
expand=YES)
b2 = Label(MyFrame2, text="Info", background="red").pack(fill=BOTH,
expand=YES)
b3 = Label(MyFrame3, text="Control",
background="green").pack(fill=BOTH, expand=YES)
b4 = Label(MyFrame3, text="NEXT 1", background="green").pack(fill=BOTH,
expand=YES)
MyFrame1.pack(side=TOP, fill=BOTH, expand=YES)
MyFrame2.pack(side=RIGHT, fill=BOTH, expand=YES)
MyFrame3.pack(side=LEFT, fill=BOTH, expand=YES)
MyFrame4.pack(side=BOTTOM, fill=BOTH, expand=YES)
MyFrame0.pack(fill=BOTH, expand=YES)
raw_input()
print "\n"*23
I get:
*******************************************
* *
* *
* *
* frame 1 *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*******************************************
* * *
* * *
* frame 3 * *
* * *
* * *
************************* frame 2 *
* * *
* * *
* frame 4 * *
* * *
* * *
*******************************************
and when I resize, all frames are resized?
Any idea why?
A related question:
Why does frame 4 not span the bottom ?
i.e.
*******************************************
* *
* *
* *
* frame 1 *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*******************************************
* * *
* * *
* frame 2 * frame 3 *
* * *
* * *
*******************************************
* *
* *
* frame 4 *
* *
* *
*******************************************
NOTE:
I am running PYTHON and Tkinter on a windows' XP box.
I am a newbie and have a few questions about Python and Tkinter.
I would like to create the following layout in Python:
*******************************************
* *
* *
* *
* frame 1 *
* *
* *
* *
* *
*******************************************
* * *
* * *
* * *
* frame 3 * frame 2 *
* * *
* * *
* * *
*******************************************
I try to accomplish this with the following code:
from Tkinter import *
root = Tk()
root.title("Critter World")
MyFrame0 = Frame(root, background="brown") # One Parent Frame to rule
them all
MyFrame1 = Frame(MyFrame0, background = "yellow")
MyFrame2 = Frame(MyFrame0, background = "red")
MyFrame3 = Frame(MyFrame0, background = "green")
b1 = Label(MyFrame1, text="World", background="yellow").pack(fill=BOTH,
expand=YES)
b2 = Label(MyFrame2, text="Info", background="red").pack(fill=BOTH,
expand=YES)
b3 = Label(MyFrame3, text="Control",
background="green").pack(fill=BOTH, expand=YES)
MyFrame1.pack(side=TOP, fill=BOTH, expand=YES)
MyFrame2.pack(side=RIGHT, fill=BOTH, expand=YES)
MyFrame3.pack(side=LEFT, fill=BOTH, expand=YES)
MyFrame0.pack(fill=BOTH, expand=YES)
raw_input()
print "\n"*23
When the window resizes, it is only Frame1 that is resized.
However, if I run the following:
from Tkinter import *
root = Tk()
root.title("Critter World")
MyFrame0 = Frame(root, background="brown") # One Parent Frame to rule
them all
MyFrame1 = Frame(MyFrame0, background="yellow")
MyFrame2 = Frame(MyFrame0, background = "red")
MyFrame3 = Frame(MyFrame0, background = "green")
MyFrame4 = Frame(MyFrame0, background = "black")
b1 = Label(MyFrame1, text="World", background="yellow").pack(fill=BOTH,
expand=YES)
b2 = Label(MyFrame2, text="Info", background="red").pack(fill=BOTH,
expand=YES)
b3 = Label(MyFrame3, text="Control",
background="green").pack(fill=BOTH, expand=YES)
b4 = Label(MyFrame3, text="NEXT 1", background="green").pack(fill=BOTH,
expand=YES)
MyFrame1.pack(side=TOP, fill=BOTH, expand=YES)
MyFrame2.pack(side=RIGHT, fill=BOTH, expand=YES)
MyFrame3.pack(side=LEFT, fill=BOTH, expand=YES)
MyFrame4.pack(side=BOTTOM, fill=BOTH, expand=YES)
MyFrame0.pack(fill=BOTH, expand=YES)
raw_input()
print "\n"*23
I get:
*******************************************
* *
* *
* *
* frame 1 *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*******************************************
* * *
* * *
* frame 3 * *
* * *
* * *
************************* frame 2 *
* * *
* * *
* frame 4 * *
* * *
* * *
*******************************************
and when I resize, all frames are resized?
Any idea why?
A related question:
Why does frame 4 not span the bottom ?
i.e.
*******************************************
* *
* *
* *
* frame 1 *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*******************************************
* * *
* * *
* frame 2 * frame 3 *
* * *
* * *
*******************************************
* *
* *
* frame 4 *
* *
* *
*******************************************
NOTE:
I am running PYTHON and Tkinter on a windows' XP box.