From 1268885f3c3f05adfd9d07c361ced9faac78ddae Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sat, 8 Sep 2018 13:54:28 -0400 Subject: [PATCH] TURNED OFF the grab_anywhere parameter for non-blocking forms. New #! line at top of file. Beginning of new Menu Element (in progress don't use) --- PySimpleGUI.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index eb5d899f..1d9032cc 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -1,4 +1,4 @@ -#!/usr/bin/env Python3 +#!/usr/bin/python3 import tkinter as tk from tkinter import filedialog from tkinter.colorchooser import askcolor @@ -12,8 +12,6 @@ import pickle import calendar - - # ----====----====----==== Constants the user CAN safely change ====----====----====----# DEFAULT_WINDOW_ICON = 'default_icon.ico' DEFAULT_ELEMENT_SIZE = (45,1) # In CHARACTERS @@ -162,6 +160,7 @@ ELEM_TYPE_INPUT_SLIDER = 10 ELEM_TYPE_INPUT_LISTBOX = 11 ELEM_TYPE_OUTPUT = 300 ELEM_TYPE_COLUMN = 555 +ELEM_TYPE_MENU = 600 ELEM_TYPE_PROGRESS_BAR = 200 ELEM_TYPE_BLANK = 100 @@ -1218,7 +1217,6 @@ class Column(Element): # ---------------------------------------------------------------------- # # Calendar # # ---------------------------------------------------------------------- # - class TKCalendar(ttk.Frame): """ This code was shamelessly lifted from moshekaplan's repository - moshekaplan/tkinter_components @@ -1428,7 +1426,27 @@ class TKCalendar(ttk.Frame): return self.datetime(year, month, int(self._selection[0])) +# ---------------------------------------------------------------------- # +# Canvas # +# ---------------------------------------------------------------------- # +class Menu(Element): + def __init__(self, text, command=None, background_color=None, scale=(None, None), size=(None, None), pad=None, key=None): + self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR + self.Command = command + self.Text = text + self.TKMenu = None + super().__init__(ELEM_TYPE_MENU, background_color=background_color, scale=scale, size=size, pad=pad, key=key) + return + + def MenuItemChosenCallback(self): + print('IN MENU ITEM CALLBACK') + self.ParentForm.LastButtonClicked = 'Menu' + self.ParentForm.FormRemainedOpen = True + self.ParentForm.TKroot.quit() # kick the users out of the mainloop + + def __del__(self): + super().__del__() # ------------------------------------------------------------------------- # @@ -2501,6 +2519,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT: element.TKCanvas.configure(background=element.BackgroundColor) element.TKCanvas.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1]) + # ------------------------- Canvas element ------------------------- # + elif element_type == ELEM_TYPE_MENU: + element.TKMenu = tk.Menu(toplevel_form.TKroot) + filemenu = tk.Menu(element.TKMenu, tearoff=0) + filemenu.add_command(label="Open", command=element.MenuItemChosenCallback) + element.TKMenu.add_cascade(label="File", menu=filemenu) + toplevel_form.TKroot.configure(menu=element.TKMenu) # ------------------------- Frame element ------------------------- # elif element_type == ELEM_TYPE_FRAME: width, height = element_size @@ -2676,7 +2701,7 @@ def StartupTK(my_flex_form): my_flex_form.TKroot = root # Make moveable window - if my_flex_form.NoTitleBar or my_flex_form.GrabAnywhere: + if (my_flex_form.NoTitleBar or my_flex_form.GrabAnywhere) and not my_flex_form.NonBlocking: root.bind("", my_flex_form.StartMove) root.bind("", my_flex_form.StopMove) root.bind("", my_flex_form.OnMotion)