简体   繁体   English

如何为框架添加边框 Python Tkinter

[英]How to add a border for a frame in Python Tkinter

Below is my UI.下面是我的用户界面。 I am trying to add a border for the frame.我正在尝试为框架添加边框。

But I am not getting any information on how to add a border.但我没有得到任何关于如何添加边框的信息。 How can I do it?我该怎么做?

边框如图所示

The requested feature is not called a border in tkinter, it is called a highlight.请求的功能在 tkinter 中不称为边框,它称为突出显示。 To get the above request, set highlightbackground="black" and highlightthickness=1 .要获得上述请求,请设置highlightbackground="black"highlightthickness=1 (The border is the empty space reserved around the frame) Additional info available in documentation: link (边框是框架周围保留的空白空间)文档中提供的其他信息: 链接

I request you to read the documentation thoroughly, and look at the styles you can apply to a frame using Tkinter: Tkinter Frame Widget我要求您彻底阅读文档,并查看您可以使用 Tkinter 应用于框架的样式: Tkinter Frame Widget

Here is how you do this:以下是您如何执行此操作:

import tkinter as tk
#tk.Frame(master, **config-options)

my_frame = tk.Frame(parent_widget, borderwidth = 1)
from tkinter import *    
root = Tk()
frame1 = Frame(root, highlightbackground="blue", highlightthickness=1,width=600, height=100, bd= 0)
frame1.pack()
root.mainloop()

-> change the options accordingly -> 相应地更改选项

-> highlightbackground used to change the color of the widget in focus -> highlightbackground用于改变焦点中小部件的颜色

-> highlightthickness used to specify the thickness of the border around the widget in focus. -> highlightthickness用于指定焦点控件周围边框的厚度。

You can use relief and borderwidth like this.您可以像这样使用浮雕和边框。

from tkinter import *    
root = Tk()
frame1 = Frame(root,width=400,height=660,bg="White",borderwidth=1,relief=RIDGE)
frame1.place(relx=0.7,y=80)
root.mainloop()

I have tried like:我试过像:

frame_left = tk.Frame(window, width=100, height=360, bg="blue", borderwidth=1, relief=tk.RIDGE)
frame_left.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
frame_right = tk.Frame(window, highlightbackground="green", highlightthickness=10, width=100, height=100, bd=0)
frame_right.pack(side=tk.RIGHT, fill=tk.BOTH, expand=1)

See the link below to for what the output of the above code looks like:请参阅下面的链接,了解上面代码的 output 是什么样子的:

https://i.stack.imgur.com/JkgAm.png https://i.stack.imgur.com/JkgAm.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM