Python tkinter._default_root() Examples
The following are 30
code examples of tkinter._default_root().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkinter
, or try the search function
.
Example #1
Source File: Dialog.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def __init__(self, master=None, title=None, buttons=OK_BUTTON, default=OK_BUTTON): master = master or tk._default_root super().__init__(master) self.withdraw() # hide until ready to show if title is not None: self.title(title) self.buttons = buttons self.default = default self.acceptButton = None self.__create_ui() self.__position() self.ok = None self.deiconify() # show if self.grid() is None: # A saner minsize than 1x1 self.minsize(80, 40) else: self.minsize(10, 5) if self.winfo_viewable(): self.transient(master) self.initialize() self.initialFocusWidget.focus() # give focus to first widget self.wait_visibility() self.grab_set() self.wait_window(self)
Example #2
Source File: ImageTk.py From lambda-text-extractor with Apache License 2.0 | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise IOError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #3
Source File: ImageTk.py From lambda-text-extractor with Apache License 2.0 | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise IOError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #4
Source File: ImageTk.py From FODI with GNU General Public License v3.0 | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) super().__init__(master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise OSError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #5
Source File: PyShell.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def begin(self): self.text.mark_set("iomark", "insert") self.resetoutput() if use_subprocess: nosub = '' client = self.interp.start_subprocess() if not client: self.close() return False else: nosub = ("==== No Subprocess ====\n\n" + "WARNING: Running IDLE without a Subprocess is deprecated\n" + "and will be removed in a later version. See Help/IDLE Help\n" + "for details.\n\n") sys.displayhook = rpc.displayhook self.write("Python %s on %s\n%s\n%s" % (sys.version, sys.platform, self.COPYRIGHT, nosub)) self.text.focus_force() self.showprompt() import tkinter tkinter._default_root = None # 03Jan04 KBK What's this? return True
Example #6
Source File: PyShell.py From ironpython3 with Apache License 2.0 | 6 votes |
def begin(self): self.text.mark_set("iomark", "insert") self.resetoutput() if use_subprocess: nosub = '' client = self.interp.start_subprocess() if not client: self.close() return False else: nosub = ("==== No Subprocess ====\n\n" + "WARNING: Running IDLE without a Subprocess is deprecated\n" + "and will be removed in a later version. See Help/IDLE Help\n" + "for details.\n\n") sys.displayhook = rpc.displayhook self.write("Python %s on %s\n%s\n%s" % (sys.version, sys.platform, self.COPYRIGHT, nosub)) self.text.focus_force() self.showprompt() import tkinter tkinter._default_root = None # 03Jan04 KBK What's this? return True
Example #7
Source File: PyShell.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def begin(self): self.text.mark_set("iomark", "insert") self.resetoutput() if use_subprocess: nosub = '' client = self.interp.start_subprocess() if not client: self.close() return False else: nosub = ("==== No Subprocess ====\n\n" + "WARNING: Running IDLE without a Subprocess is deprecated\n" + "and will be removed in a later version. See Help/IDLE Help\n" + "for details.\n\n") sys.displayhook = rpc.displayhook self.write("Python %s on %s\n%s\n%s" % (sys.version, sys.platform, self.COPYRIGHT, nosub)) self.text.focus_force() self.showprompt() import tkinter tkinter._default_root = None # 03Jan04 KBK What's this? return True
Example #8
Source File: ImageTk.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise IOError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #9
Source File: PlatformManagerDarwin.py From lackey with MIT License | 6 votes |
def _do_until_timeout(self, queue, args): rect, color, seconds = args if tk._default_root is None: Debug.log(3, "Creating new temporary Tkinter root") temporary_root = True root = tk.Tk() root.withdraw() else: Debug.log(3, "Borrowing existing Tkinter root") temporary_root = False root = tk._default_root image_to_show = self.getBitmapFromRect(*rect) app = highlightWindow(root, rect, color, image_to_show, queue) app.do_until_timeout(seconds) ## Process functions
Example #10
Source File: ImageTk.py From teleport with Apache License 2.0 | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) super().__init__(master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise OSError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #11
Source File: ImageTk.py From teleport with Apache License 2.0 | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) super().__init__(master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise OSError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #12
Source File: ImageTk.py From teleport with Apache License 2.0 | 6 votes |
def _show(image, title): """Helper for the Image.show method.""" class UI(tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0) if not tkinter._default_root: raise IOError("tkinter not initialized") top = tkinter.Toplevel() if title: top.title(title) UI(top, image).pack()
Example #13
Source File: ui_utils.py From thonny with MIT License | 5 votes |
def __init__(self, title, text_content, parent=None): if parent is None: parent = tk._default_root super().__init__(master=parent) self.title(title) main_frame = ttk.Frame(self) main_frame.grid(row=0, column=0, sticky="nsew") self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) default_font = tk.font.nametofont("TkDefaultFont") self._text = tktextext.TextFrame( main_frame, read_only=True, wrap="none", font=default_font, width=80, height=10, relief="sunken", borderwidth=1, ) self._text.grid(row=1, column=0, columnspan=2, sticky="nsew", padx=20, pady=20) self._text.text.direct_insert("1.0", text_content) self._text.text.see("1.0") copy_button = ttk.Button( main_frame, command=self._copy, text=_("Copy to clipboard"), width=20 ) copy_button.grid(row=2, column=0, sticky="w", padx=20, pady=(0, 20)) close_button = ttk.Button(main_frame, command=self._close, text=_("Close")) close_button.grid(row=2, column=1, sticky="w", padx=20, pady=(0, 20)) main_frame.columnconfigure(0, weight=1) main_frame.rowconfigure(1, weight=1) self.protocol("WM_DELETE_WINDOW", self._close) self.bind("<Escape>", self._close, True)
Example #14
Source File: tix.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def image_create(self, imgtype, cnf={}, master=None, **kw): if not master: master = tkinter._default_root if not master: raise RuntimeError('Too early to create image') if kw and cnf: cnf = _cnfmerge((cnf, kw)) elif kw: cnf = kw options = () for k, v in cnf.items(): if callable(v): v = self._register(v) options = options + ('-'+k, v) return master.tk.call(('image', 'create', imgtype,) + options)
Example #15
Source File: tix.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def __init__(self, itemtype, cnf={}, **kw): if 'refwindow' in kw: master = kw['refwindow'] elif 'refwindow' in cnf: master = cnf['refwindow'] else: master = tkinter._default_root if not master: raise RuntimeError("Too early to create display style: " "no root window") self.tk = master.tk self.stylename = self.tk.call('tixDisplayStyle', itemtype, *self._options(cnf,kw) )
Example #16
Source File: font.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def __init__(self, root=None, font=None, name=None, exists=False, **options): if not root: root = tkinter._default_root tk = getattr(root, 'tk', root) if font: # get actual settings corresponding to the given font font = tk.splitlist(tk.call("font", "actual", font)) else: font = self._set(options) if not name: name = "font" + str(next(self.counter)) self.name = name if exists: self.delete_font = False # confirm font exists if self.name not in tk.splitlist(tk.call("font", "names")): raise tkinter._tkinter.TclError( "named font %s does not already exist" % (self.name,)) # if font config info supplied, apply it if font: tk.call("font", "configure", self.name, *font) else: # create new font (raises TclError if the font exists) tk.call("font", "create", self.name, *font) self.delete_font = True self._tk = tk self._split = tk.splitlist self._call = tk.call
Example #17
Source File: font.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def families(root=None, displayof=None): "Get font families (as a tuple)" if not root: root = tkinter._default_root args = () if displayof: args = ('-displayof', displayof) return root.tk.splitlist(root.tk.call("font", "families", *args))
Example #18
Source File: support.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def tearDownClass(cls): cls.root.update_idletasks() cls.root.destroy() del cls.root tkinter._default_root = None tkinter._support_default_root = cls._old_support_default_root
Example #19
Source File: support.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def destroy_default_root(): if getattr(tkinter, '_default_root', None): tkinter._default_root.update_idletasks() tkinter._default_root.destroy() tkinter._default_root = None
Example #20
Source File: test_extensions.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_initialization_no_master(self): # no master passing with swap_attr(tkinter, '_default_root', None), \ swap_attr(tkinter, '_support_default_root', True): try: x = ttk.LabeledScale() self.assertIsNotNone(tkinter._default_root) self.assertEqual(x.master, tkinter._default_root) self.assertEqual(x.tk, tkinter._default_root.tk) x.destroy() finally: destroy_default_root()
Example #21
Source File: ttk.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setup_master(master=None): """If master is not None, itself is returned. If master is None, the default master is returned if there is one, otherwise a new master is created and returned. If it is not allowed to use the default root and master is None, RuntimeError is raised.""" if master is None: if tkinter._support_default_root: master = tkinter._default_root or tkinter.Tk() else: raise RuntimeError( "No master specified and tkinter is " "configured to not support default root") return master
Example #22
Source File: ui_utils.py From thonny with MIT License | 5 votes |
def get_tk_version_str(): return tk._default_root.tk.call("info", "patchlevel")
Example #23
Source File: ui_utils.py From thonny with MIT License | 5 votes |
def show_dialog(dlg, master=None, geometry=True, min_left=0, min_top=0): if getattr(dlg, "closed", False): return if master is None: master = tk._default_root get_workbench().event_generate("WindowFocusOut") # following order seems to give most smooth appearance focused_widget = master.focus_get() dlg.transient(master.winfo_toplevel()) if geometry: # dlg.withdraw() # unfortunately inhibits size calculations in assign_geometry if isinstance(geometry, str): dlg.geometry(geometry) else: assign_geometry(dlg, master, min_left, min_top) # dlg.wm_deiconify() try: dlg.grab_set() except: pass dlg.lift() dlg.focus_set() master.winfo_toplevel().wait_window(dlg) dlg.grab_release() master.winfo_toplevel().lift() master.winfo_toplevel().focus_force() master.winfo_toplevel().grab_set() if running_on_mac_os(): master.winfo_toplevel().grab_release() if focused_widget is not None: try: focused_widget.focus_force() except TclError: pass
Example #24
Source File: codeview.py From thonny with MIT License | 5 votes |
def __init__(self, master=None, cnf={}, **kw): if "replace_tabs" not in kw: kw["replace_tabs"] = False super().__init__( master=master, tag_current_line=get_workbench().get_option("view.highlight_current_line"), cnf=cnf, **kw ) # Allow binding to events of all CodeView texts self.bindtags(self.bindtags() + ("CodeViewText",)) tktextext.fixwordbreaks(tk._default_root)
Example #25
Source File: misc_utils.py From thonny with MIT License | 5 votes |
def find_volume_by_name( volume_name: str, not_found_msg: Optional[str] = None, found_several_msg: Optional[str] = None ) -> Optional[str]: # Can't translate in the header as _ may not be available at import time if not_found_msg is None: not_found_msg = _("Could not find disk '%s'. Do you want to locate it yourself?") if found_several_msg is None: found_several_msg = _("Found several '%s' disks. Do you want to choose one yourself?") volumes = find_volumes_by_name(volume_name) if len(volumes) == 1: return volumes[0] else: if len(volumes) == 0: msg = not_found_msg % volume_name else: msg = found_several_msg % volume_name from tkinter.messagebox import askyesno from thonny.ui_utils import askdirectory import tkinter as tk if askyesno(_("Can't find suitable disk"), msg): path = askdirectory(master=tk._default_root) if path: return path return None
Example #26
Source File: workbench.py From thonny with MIT License | 5 votes |
def report_exception(self, title: str = "Internal error") -> None: logging.exception(title) if tk._default_root and not self._closing: # type: ignore (typ, value, _) = sys.exc_info() assert typ is not None if issubclass(typ, UserError): msg = str(value) else: msg = traceback.format_exc() dlg = ui_utils.LongTextDialog(title, msg, parent=self) ui_utils.show_dialog(dlg, self)
Example #27
Source File: PlatformManagerWindows.py From lackey with MIT License | 5 votes |
def highlight(self, rect, color="red", seconds=None): """ Simulates a transparent rectangle over the specified ``rect`` on the screen. Actually takes a screenshot of the region and displays with a rectangle border in a borderless window (due to Tkinter limitations) If a Tkinter root window has already been created somewhere else, uses that instead of creating a new one. """ if tk._default_root is None: Debug.log(3, "Creating new temporary Tkinter root") temporary_root = True root = tk.Tk() root.withdraw() else: Debug.log(3, "Borrowing existing Tkinter root") temporary_root = False root = tk._default_root image_to_show = self.getBitmapFromRect(*rect) app = highlightWindow(root, rect, color, image_to_show) if seconds == 0: t = threading.Thread(target=app.do_until_timeout) t.start() return app app.do_until_timeout(seconds) ## Process functions
Example #28
Source File: barchart2.py From python-in-practice with GNU General Public License v3.0 | 5 votes |
def initialize(self, bars, maximum): assert bars > 0 and maximum > 0 if tk._default_root is None: self.gui = tk.Tk() self.inGui = False else: self.gui = tk._default_root self.inGui = True self.index = 0 self.width = bars * (self.barWidth + self.barGap) self.height = maximum * self.stepHeight self.image = tk.PhotoImage(width=self.width, height=self.height) self.image.put("white", (0, 0, self.width, self.height))
Example #29
Source File: test_extensions.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_initialization_no_master(self): # no master passing with swap_attr(tkinter, '_default_root', None), \ swap_attr(tkinter, '_support_default_root', True): try: x = ttk.LabeledScale() self.assertIsNotNone(tkinter._default_root) self.assertEqual(x.master, tkinter._default_root) self.assertEqual(x.tk, tkinter._default_root.tk) x.destroy() finally: destroy_default_root()
Example #30
Source File: ttk.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def setup_master(master=None): """If master is not None, itself is returned. If master is None, the default master is returned if there is one, otherwise a new master is created and returned. If it is not allowed to use the default root and master is None, RuntimeError is raised.""" if master is None: if tkinter._support_default_root: master = tkinter._default_root or tkinter.Tk() else: raise RuntimeError( "No master specified and tkinter is " "configured to not support default root") return master