在Tkinter网格上绘图 [英] Drawing on Tkinter grid

查看:150
本文介绍了在Tkinter网格上绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何使用网格绘制线的方法.我想要一条从北到南的线,将左右框架分开.

I couldn't find a way how to Draw line using grid. I want to have a line going from North to South seperating left and right frames.

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

推荐答案

如果要将左框架与右框架分开,则可以使用ttk模块(

If you want to separate the left frame from the right one, you can use a separator from ttk module (http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Separator.html)

这里是一个例子:

# 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()

这篇关于在Tkinter网格上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆