FullMetalJumper
FullMetalJumper

Reputation: 13

Menu interferring with save prompt

I am experiencing an issue where if I introduce a user choice menu into my code, a function that produces a save dialog will not appear. If I comment out the menu function then everything works. A sample of my code is below. I have ripped out a lot of other functions so only the minimum is presented below and will not make any sense but the code does work when commenting out the save_forms def. I've only been at this for a few weeks so any constructive criticism would be appreciated.

import time
import sys
from tkinter import *
from tkinter import filedialog as fd

global OU
global tempdir
global fs

def menu():

    print("[1] Number 1")
    print("[2] Number 2")
    print("[0] Exit")

    ou_option = int(input("Enter a number: "))

    if ou_option == 1:
        print("Number 1 selected")
        OU = str("Number1")
    elif ou_option == 2:
        print("Number 2 selected")
        OU = str("Number2")
    elif ou_option == 0:
        print("Exiting")
        time.sleep(1)
        sys.exit()
    else:
        print("Invalid number. Try again...")
        menu()

def save_forms():
    tk2 = Tk()
    tk2.withdraw()

    fs = fd.askdirectory(title='Select output folder')

    if not fs:
        print('User Cancelled')
        time.sleep(1)
        sys.exit()
    else:
        print('Saving...')

menu()
print("Saving Form")
save_forms()

Upvotes: 0

Views: 24

Answers (1)

FullMetalJumper
FullMetalJumper

Reputation: 13

Using tk1.attributes("-topmost", True) brings the dialog to the front. Thanks Bill for the point in the right direction.

Upvotes: 1

Related Questions