菜合馍馍
菜合馍馍

Reputation: 137

Python simpledialog location and hide blank

This is my code

import tkinter as tk
from tkinter import simpledialog
root = tk.Tk()
# root.withdraw()
root.geometry("340x100+50+500")
user_input = simpledialog.askfloat(title="输入框", prompt="请输入内容:", parent=root, initialvalue=34)
user_input = user_input * 60
root.destroy()

When it's run, there was a blank form underneath it, and I wanted to hide it, so I added a piece of code

root.withdraw()

But the root.geometry("340x100+50+500") is not work

so how i do the root.withdraw() and root.geometry("340x100+50+500") both work?

Upvotes: 0

Views: 71

Answers (2)

菜合馍馍
菜合馍馍

Reputation: 137

import tkinter as tk
from tkinter import simpledialog
root = tk.Tk()
root.wm_attributes('-alpha', 0.0)
root.geometry("340x100+50+500")
user_input = simpledialog.askfloat(title="输入框", prompt="请输入内容:", parent=root, initialvalue=34)
user_input = user_input * 60
root.destroy()

add root.wm_attributes('-alpha', 0.0) it's work

Upvotes: 0

toyota Supra
toyota Supra

Reputation: 4560

When it's run, there was a blank form underneath it, and I wanted to hide it

Pay attention to @Bryan Oakley and @acw1668

The problem can be fixed.

Pay attention to @Bryan Oakley and @acw1668

Move root.withdraw() after root.geometry(...)

Snippet:

:
root.geometry("340x100+50+500")
root.withdraw()
:

Screenshot:

enter image description here

Upvotes: 1

Related Questions