我想要弹出窗口上有红色边框。边框宽度有效,但颜色无效。边框颜色仍然是黑色,而不是红色。我尝试了两种不同的方法。两者都有黑色边框。
方法#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()