使用tkinter和scrolledText,我想创建一个带有红色边框的弹出窗口

问题描述 投票:0回答:1

我想要弹出窗口上有红色边框。边框宽度有效,但颜色无效。边框颜色仍然是黑色,而不是红色。我尝试了两种不同的方法。两者都有黑色边框。

方法#1(首选)

import tkinter as tk
from tkinter.scrolledtext import ScrolledText


                def display_dataframe():

                    # Create a tkinter window
                    window = tk.Tk()
                    window.title('Stock Alert')

                    # Create a scrolled text widget to display the DataFrame

                    text_widget = ScrolledText(window, width=100, height=15, borderwidth=5, relief="solid", highlightbackground="red")
                    text_widget.insert(tk.END, alert_list_display.to_string(index=False))  # Insert DataFrame content
                    text_widget.pack()

                    # Start the tkinter main loop
                    window.mainloop()

                # Call the function to display the DataFrame in a pop-up window
                display_dataframe()

方法#2

import tkinter as tk
from tkinter import scrolledtext

def change_border_color(frame, color):
    frame.configure(highlightbackground=color)

# Create a tkinter window
window = tk.Tk()
window.title('ScrolledText Border Color')

# Create a custom frame with a ScrolledText widget
frame = tk.Frame(window, borderwidth=10, relief="solid", highlightbackground="red")
frame.pack()

text_widget = scrolledtext.ScrolledText(frame, width=100, height=15)
text_widget.pack(fill="both", expand=True)

# Change the border color of the custom frame
change_border_color(frame, "blue")

# Start the tkinter main loop
window.mainloop()
tkinter colors border tkinter-scrolledtext
1个回答
0
投票

最简单的解决方案是为滚动文本的父级着色,并使用填充使滚动文本周围的区域可见。

© www.soinside.com 2019 - 2024. All rights reserved.