Python Forum
Combine console script + GUI (tkinter)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combine console script + GUI (tkinter)
#3
This is a low rent way of doing what you want with the dialog.
import ttkbootstrap as ttk

def get_dates(start=None, end=None, format="%Y/%m/%d"):
    """Draw dialog for selecting start and end dates."""
    root = ttk.Window()
    root.title("Enter Dates")

    # If window is destroyed we cannot get the date values.
    # Override what the close button does.
    root.wm_protocol("WM_DELETE_WINDOW", root.quit)
    frame = ttk.Frame(root)
    frame.pack(padx=10, pady=10)

    ttk.Label(frame, text="Start Date").grid(row=0, column=0, pady=(0, 10))
    start = ttk.DateEntry(frame, start_date=start, dateformat=format)
    start.grid(row=0, column=1, pady=(0, 10))

    ttk.Label(frame, text="End Date").grid(row=1, column=0, pady=(0, 10))
    end = ttk.DateEntry(frame, start_date=end, dateformat=format)
    end.grid(row=1, column=1, pady=(0, 10))

    done = ttk.Button(frame, text="Done", command=root.quit)
    done.grid(row=2, column=0, columnspan=2, sticky="news")

    # Wait until the done button or close decoration are pressed.
    root.mainloop()

    # Get dates before destroying the window.
    start = start.entry.get()
    end = end.entry.get()
    root.destroy()
    return start, end

print(get_dates())
The script that used the dialog is just a print() statement, but I think you can see how the dialog would get used in a longer script.
Reply


Messages In This Thread
Combine console script + GUI (tkinter) - by dejot - Feb-21-2024, 07:56 PM
RE: Combine console script + GUI (tkinter) - by deanhystad - Feb-27-2024, 04:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Make console show after script was built with Pyinstaller --NOCONSOLE? H84Gabor 0 1,235 May-05-2022, 12:32 PM
Last Post: H84Gabor
  Encountering `importlib_metadata.PackageNotFoundError` trying to run console script gretchenfrage 0 5,657 Jul-08-2021, 09:26 PM
Last Post: gretchenfrage
  IPython console vs Spyder script losc 3 2,762 Apr-30-2020, 04:57 AM
Last Post: deanhystad
  Problem running script within console koepjo 3 9,938 Mar-26-2020, 07:11 AM
Last Post: koepjo
  Is there any way to convert a python script (with Tkinter module), to a .exe (Windows moste 3 4,052 May-12-2019, 12:02 PM
Last Post: snippsat
  Spyder : Clear IPython Console whenever I re-run the script smallabc 0 5,287 Mar-04-2018, 08:05 AM
Last Post: smallabc
  Dict KeyError in cgi-bin script, works fine via console dbsoundman 2 3,940 Jul-21-2017, 08:03 PM
Last Post: dbsoundman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020