Python 在Tkinter网格上绘制
我找不到一种方法如何用网格画线。我想要一条从北到南的线,将左右帧分开Python 在Tkinter网格上绘制,python,tkinter,grid,Python,Tkinter,Grid,我找不到一种方法如何用网格画线。我想要一条从北到南的线,将左右帧分开 self.left= Frame(self.tk, bg="black") self.left.grid(column=0, row = 0, pady=5 ,padx=10, sticky=N) self.center = Frame (self.tk ,bg= "black") self.center.grid(column=1, row = 0, pady=5,padx=10, stic
self.left= Frame(self.tk, bg="black")
self.left.grid(column=0, row = 0, pady=5 ,padx=10, sticky=N)
self.center = Frame (self.tk ,bg= "black")
self.center.grid(column=1, row = 0, pady=5,padx=10, sticky=N)
self.right= Frame(self.tk, bg="black")
self.right.grid(column=2, row = 0, pady=5,padx=10, sticky=N)
我想要像这样的东西
self.w.create_rectangle(self.centerwidth/2-2, 0, centerwidth/2+2, self.windowheigh, fill="#00CC00", outline = "#00CC00")
我不知道你到底想要什么,但你可以创建这样一条线
from Tkinter import *
master = Tk()
w = Canvas(master, width=200, height=100)
w.pack()
w.create_line(100, 0, 100, 100)
#first 2 args are starting point of line and next 2 are ending point of line.
mainloop()
要添加其他选项,请参阅我不知道您到底想要什么,但您可以创建这样一行
from Tkinter import *
master = Tk()
w = Canvas(master, width=200, height=100)
w.pack()
w.create_line(100, 0, 100, 100)
#first 2 args are starting point of line and next 2 are ending point of line.
mainloop()
要添加其他选项,请参阅如果要将左帧与右帧分开,可以使用ttk模块()中的分隔符 以下是一个例子:
# python3
import tkinter as tk
from tkinter.ttk import Separator, Style
# for python2 :
# import Tkinter as tk
# from ttk import Separator
fen = tk.Tk()
left = tk.Frame(fen, bg="black",width=100, height=100)
# to prevent the frame from adapting to its content :
left.pack_propagate(False)
tk.Label(left, text="Left frame", fg="white", bg="black", anchor="center", justify="center").pack()
left.grid(column=0, row = 0, pady=5 ,padx=10, sticky="n")
sep = Separator(fen, orient="vertical")
sep.grid(column=1, row=0, sticky="ns")
# edit: To change the color of the separator, you need to use a style
sty = Style(fen)
sty.configure("TSeparator", background="red")
right= tk.Frame(fen, bg="black",width=100, height=100)
right.pack_propagate(False)
tk.Label(right, text="Right frame", fg="white", bg="black").pack()
right.grid(column=2, row = 0, pady=5,padx=10, sticky="n")
fen.mainloop()
如果要将左帧与右帧分开,可以使用ttk模块()中的分隔符 以下是一个例子:
# python3
import tkinter as tk
from tkinter.ttk import Separator, Style
# for python2 :
# import Tkinter as tk
# from ttk import Separator
fen = tk.Tk()
left = tk.Frame(fen, bg="black",width=100, height=100)
# to prevent the frame from adapting to its content :
left.pack_propagate(False)
tk.Label(left, text="Left frame", fg="white", bg="black", anchor="center", justify="center").pack()
left.grid(column=0, row = 0, pady=5 ,padx=10, sticky="n")
sep = Separator(fen, orient="vertical")
sep.grid(column=1, row=0, sticky="ns")
# edit: To change the color of the separator, you need to use a style
sty = Style(fen)
sty.configure("TSeparator", background="red")
right= tk.Frame(fen, bg="black",width=100, height=100)
right.pack_propagate(False)
tk.Label(right, text="Right frame", fg="white", bg="black").pack()
right.grid(column=2, row = 0, pady=5,padx=10, sticky="n")
fen.mainloop()
呃,我还以为你不能在里面用背包呢grid@IrenaJodeikiene:你可以在同一个应用程序中使用pack和grid,只是不能与多个具有相同父级的小部件一起使用。嗯,我以为你不能在内部使用packgrid@IrenaJodeikiene:您可以在同一应用程序中使用pack和grid,只是不能使用多个具有共同父控件的小部件。顺便问一下,您如何更改线条的颜色?顺便问一下,您如何更改线条的颜色?