Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

python 3.x - Unexpected Blank Window Tkinter

A blank window along with the main window is created.

I've seen other questions but my case is different I'm not using any constructor. The blank window appears when I initialize ttk.style.

correct_style = ttk.Style()
correct_style.configure('correct.TButton',background='#39b54a')
root = ThemedTk(theme="equilux")

If I delete these lines, the empty window doesn't appear.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you call the two lines before creating the instance of Tk(), something like below:

import tkinter as tk
from tkinter import ttk

correct_style = ttk.Style()
correct_style.configure('correct.TButton',background='#39b54a')

root = tk.Tk()
...
root.mainloop()

As ttk.Style() requires an instance of Tk(), if there is none, it will be created implicitly for you. So there will be two instances of Tk().

Move the two lines after creating Tk():

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

correct_style = ttk.Style()
correct_style.configure('correct.TButton',background='#39b54a')

...
root.mainloop()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...