繁体   English   中英

为什么单击文本小部件后出现框架边框/线条(框架在画布内)tkinter

[英]Why frame border / line appear after click text widget (the frame is inside canvas) tkinter

我在使用 python tkinter 制作 GUI 应用程序时遇到了问题。

这是我的示例代码

import tkinter as tk

from tkinter import ttk

root = tk.Tk()

root.geometry('300x300')

root.title('CSV Editor')

notebook = ttk.Notebook(root)

notebook.pack(pady=10, expand=True)

tab_home = ttk.Frame(notebook, width=300, height=300)

notebook.add(tab_home, text='Home')

fr_home = tk.Frame(tab_home, background="white")

fr_home.grid(row=0, column=0)

fr_home_container_canvas = tk.Frame(fr_home, background="red")

fr_home_container_canvas.grid(row=0, column=0, sticky='nw')

fr_home_container_canvas.grid_rowconfigure(0, weight=1)

fr_home_container_canvas.grid_columnconfigure(0, weight=1)

fr_home_container_canvas.grid_propagate(False)

canvas_home = tk.Canvas(fr_home_container_canvas)

canvas_home.grid(row=0, column=0, sticky="news")

vsb = tk.Scrollbar(fr_home_container_canvas, orient="vertical", command=canvas_home.yview)

vsb.grid(row=0, column=1, sticky='ns')

canvas_home.configure(yscrollcommand=vsb.set)

fr_home_widget_canvas = tk.Frame(canvas_home, background="yellow")

canvas_home.create_window((0, 0), window=fr_home_widget_canvas, anchor='nw')

fr_home_widget_canvas.config(width=300, height=300, padx=10)

fr_home_container_canvas.config(width=300, height=300)

canvas_home.config(scrollregion=canvas_home.bbox("all"))


text_widget = tk.Text(fr_home_widget_canvas, width = 30, height = 10)

text_widget.grid(column=0, row=0)

root.mainloop()

如果我运行此代码,这是预览在此处输入图像描述

但是当我在文本小部件内单击时,在框架中出现这样的线条/边框在此处输入图像描述

那条线/边界是什么? 如何删除它?

太感谢了:)

它是高亮背景,可以通过设置highlightthickness=0来移除:

canvas_home = tk.Canvas(fr_home_container_canvas, highlightthickness=0)

暂无
暂无

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

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