2

I am using python 3.6 and have the following issue. These lines of codes apparently open two windows, but I only expect one to be opened.

from tkinter.filedialog import asksaveasfilename

file_name = asksaveasfilename()
root.withdraw()
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Zorg
  • 79
  • 1
  • 11

2 Answers2

4

IIRC, you're supposed to call withdraw before you call asksaveasfilename. Same as in Choosing a file in Python with simple Dialog.

import tkinter
from tkinter.filedialog import asksaveasfilename

tkinter.Tk().withdraw()
file_name = asksaveasfilename()
Kevin
  • 74,910
  • 12
  • 133
  • 166
1

when you do filename = asksaveasfilename() you call the function and that makes tkinter open the second window put that in a function and on a button click the second window will open

from tkinter.filedialog import asksaveasfilename
import tkinter

root = tkinter.Tk()
root.withdraw()
asksaveasfilename()
dsal3389
  • 658
  • 1
  • 7
  • 26
  • Sorry I dont get it. tkiner opens a seconde windwo because why? – Zorg Jun 07 '18 at 19:12
  • and I dont want a button, the window should open whene the code is executed. – Zorg Jun 07 '18 at 19:14
  • https://stackoverflow.com/questions/1406145/how-do-i-get-rid-of-python-tkinter-root-window?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – dsal3389 Jun 07 '18 at 19:21