本文整理汇总了Python中tkinter._default_root方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter._default_root方法的具体用法?Python tkinter._default_root怎么用?Python tkinter._default_root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter._default_root方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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)
示例2: _do_until_timeout
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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
示例3: _show
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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()
示例4: _show
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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()
示例5: begin
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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
示例6: initialize
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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))
示例7: highlight
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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
示例8: setup_master
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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
示例9: image_create
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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)
示例10: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
def __init__(self, itemtype, cnf={}, **kw):
master = _default_root # global from Tkinter
if not master and 'refwindow' in cnf: master=cnf['refwindow']
elif not master and 'refwindow' in kw: master= kw['refwindow']
elif 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) )
示例11: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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
示例12: families
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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))
示例13: tearDownClass
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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
示例14: destroy_default_root
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
def destroy_default_root():
if getattr(tkinter, '_default_root', None):
tkinter._default_root.update_idletasks()
tkinter._default_root.destroy()
tkinter._default_root = None
示例15: test_initialization_no_master
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import _default_root [as 别名]
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()