Python tkinter设置比例(创建2x2方框)
我想在python的tkinter中创建一个2乘2的框,它将成为我的“世界”。 有没有办法在“世界”上设置X轴和Y轴 比如:Python tkinter设置比例(创建2x2方框),python,tkinter,Python,Tkinter,我想在python的tkinter中创建一个2乘2的框,它将成为我的“世界”。 有没有办法在“世界”上设置X轴和Y轴 比如: setXscale(-1.0, +1.0); setYscale(-1.0, +1.0); 这可以通过.pack()方法完成,如下所示: from tkinter import * root = Tk() top = Frame(root) bottom = Frame(root) topleft = Frame(top) topright = Frame(
setXscale(-1.0, +1.0);
setYscale(-1.0, +1.0);
这可以通过
.pack()
方法完成,如下所示:
from tkinter import *
root = Tk()
top = Frame(root)
bottom = Frame(root)
topleft = Frame(top)
topright = Frame(top)
bottomleft = Frame(bottom)
bottomright = Frame(bottom)
lbl1 = Label(topleft, text="topleft")
lbl2 = Label(topright, text="topright")
lbl3 = Label(bottomleft, text="bottomleft")
lbl4 = Label(bottomright, text="bottomright")
top.pack(side="top")
bottom.pack(side="bottom")
topleft.pack(side="left")
topright.pack(side="right")
bottomleft.pack(side="left")
bottomright.pack(side="right")
lbl1.pack()
lbl2.pack()
lbl3.pack()
lbl4.pack()
root.mainloop()
这将创建一个顶部
帧和一个底部
帧,每个帧都包含一个左右帧。
然后将这些帧打包到各自的侧
或者,使用
.grid()
这样做会容易得多:
from tkinter import *
root = Tk()
topleft = Frame(root)
topright = Frame(root)
bottomleft = Frame(root)
bottomright = Frame(root)
lbl1 = Label(topleft, text="topleft")
lbl2 = Label(topright, text="topright")
lbl3 = Label(bottomleft, text="bottomleft")
lbl4 = Label(bottomright, text="bottomright")
topleft.grid(row = 0, column = 0)
topright.grid(row = 0, column = 1)
bottomleft.grid(row = 1, column = 0)
bottomright.grid(row = 1, column = 1)
lbl1.grid(row = 0, column = 0)
lbl2.grid(row = 0, column = 0)
lbl3.grid(row = 0, column = 0)
lbl4.grid(row = 0, column = 0)
root.mainloop()
from tkinter import *
root = Tk()
lbl1 = Label(root, text="topleft")
lbl2 = Label(root, text="topright")
lbl3 = Label(root, text="bottomleft")
lbl4 = Label(root, text="bottomright")
lbl1.grid(row = 0, column = 0)
lbl2.grid(row = 0, column = 1)
lbl3.grid(row = 1, column = 0)
lbl4.grid(row = 1, column = 1)
root.mainloop()
或者像这样:
from tkinter import *
root = Tk()
topleft = Frame(root)
topright = Frame(root)
bottomleft = Frame(root)
bottomright = Frame(root)
lbl1 = Label(topleft, text="topleft")
lbl2 = Label(topright, text="topright")
lbl3 = Label(bottomleft, text="bottomleft")
lbl4 = Label(bottomright, text="bottomright")
topleft.grid(row = 0, column = 0)
topright.grid(row = 0, column = 1)
bottomleft.grid(row = 1, column = 0)
bottomright.grid(row = 1, column = 1)
lbl1.grid(row = 0, column = 0)
lbl2.grid(row = 0, column = 0)
lbl3.grid(row = 0, column = 0)
lbl4.grid(row = 0, column = 0)
root.mainloop()
from tkinter import *
root = Tk()
lbl1 = Label(root, text="topleft")
lbl2 = Label(root, text="topright")
lbl3 = Label(root, text="bottomleft")
lbl4 = Label(root, text="bottomright")
lbl1.grid(row = 0, column = 0)
lbl2.grid(row = 0, column = 1)
lbl3.grid(row = 1, column = 0)
lbl4.grid(row = 1, column = 1)
root.mainloop()
所以你只是想在一个固定大小的2x2网格中创建4个
帧
s?是的。在这个框中,我将创建标签等,必须使用而不是pack
…这个比例中的数字代表什么?一行有多少个盒子?框中的像素数?列号?