本文整理汇总了Python中tkinter.Toplevel.mainloop方法的典型用法代码示例。如果您正苦于以下问题:Python Toplevel.mainloop方法的具体用法?Python Toplevel.mainloop怎么用?Python Toplevel.mainloop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Toplevel
的用法示例。
在下文中一共展示了Toplevel.mainloop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
class InfoWindow:
def __init__(self, model: World):
self.model = model
self.window = Toplevel()
self.window.title('Информация об объектах и мире')
self.window.geometry("640x600+250+200")
self._inner_init()
self.frame.pack()
self.window.mainloop()
def _inner_init(self):
self.frame = Frame(self.window,
width=640,
height=600,
bd=2)
self.frame.grid_bbox(2, 2)
self._about_world()
self._about_creatures()
def _about_world(self):
self.world_indo = self.model.info()
TEXT = "Кол-во объектов: {cr_count}\n" \
"Из них живые: {cr_alive}".format(**self.world_indo)
Label(self.frame,
text=TEXT).grid(row=1, column=1)
def _about_creatures(self):
lb = Listbox(self.frame,
height=15,
width=50,
selectmode=SINGLE)
lb.bind('<<ListboxSelect>>', self._onselect)
lb.grid(row=1, column=2)
items = self.model.creatures.items()
items = sorted(items, key=lambda k: k[0][0] * self.model.width + k[0][1])
for (x, y), creature in items:
lb.insert(END, [x, y, creature.life])
self.canvas = NeuroCanvas(self.frame, (2, 2), 400, 300)
def _onselect(self, evt):
w = evt.widget
index = int(w.curselection()[0])
value = w.get(index)
x, y, *_ = value[1:].split(",")
x = int(x)
y = int(y)
cr = self.model.creatures[(x, y)]
neuro = cr.genome
self.canvas.draw(neuro)
示例2: __init__
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
class SpeciesListDialog:
def __init__(self, parent):
self.parent = parent
self.gui = Toplevel(parent.guiRoot)
self.gui.grab_set()
self.gui.focus()
self.gui.columnconfigure(0, weight=1)
self.gui.rowconfigure(1, weight=1)
Label(self.gui, text="Registered Species:").grid(row=0, column=0, pady=5, padx=5, sticky="w")
self.listRegisteredSpecies = Listbox(self.gui, width=70)
self.buttonAdd = Button(self.gui, text=" + ")
self.buttonDel = Button(self.gui, text=" - ")
self.listRegisteredSpecies.grid(row=1, column=0, columnspan=3, sticky="nswe", pady=5, padx=5)
self.buttonAdd.grid(row=2, column=1, pady=5, padx=5)
self.buttonDel.grid(row=2, column=2, pady=5, padx=5)
# Set (minimum + max) Window size
self.gui.update()
self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
# self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())
self.actionUpdate(None)
self.gui.bind("<<Update>>", self.actionUpdate)
self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)
self.buttonDel.bind("<ButtonRelease>", self.actionDel)
self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
self.gui.mainloop()
def actionClose(self):
self.parent.guiRoot.event_generate("<<Update>>", when="tail")
self.gui.destroy()
def actionUpdate(self, event):
self.listRegisteredSpecies.delete(0, "end")
for (taxid, name) in self.parent.optimizer.speciesList:
self.listRegisteredSpecies.insert("end", taxid + ": " + name)
def actionDel(self, event):
try:
selection = self.listRegisteredSpecies.selection_get()
selectionSplit = selection.split(": ")
self.parent.optimizer.speciesList.remove((selectionSplit[0], selectionSplit[1]))
self.gui.event_generate("<<Update>>")
except tkinter.TclError:
# no selection
pass
def actionAdd(self, Event):
SpeciesSearchDialog(self.parent, self)
示例3: askgridprop
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
def askgridprop():
win = Toplevel()
color = ['#000000', '#000000']
propvars = [StringVar() for i in range(4)]
guidata = (
{
'linestyle': ('Major Line Style', propvars[0], None),
'linewidth': ('Major Line Width', propvars[1], check_nonnegative_float)
},
{
'linestyle': ('Minor Line Style', propvars[2], None),
'linewidth': ('Minor Line Width', propvars[3], check_nonnegative_float)
}
)
for d in guidata:
for key in d:
pitem = LabeledEntry(win)
pitem.pack()
pitem.label_text = d[key][0]
pitem.entry['textvariable'] = d[key][1]
if d[key][2]:
pitem.checker_function = d[key][2]
def setmajorcolor():
c = askcolor()
color[0] = c[1]
def setminorcolor():
c = askcolor()
color[1] = c[1]
Button(win, text='Major Line Color', command=setmajorcolor).pack()
Button(win, text='Minor Line Color', command=setminorcolor).pack()
win.protocol('WM_DELETE_WINDOW', win.quit)
win.focus_set()
win.grab_set()
win.mainloop()
win.destroy()
c_major = StringVar(); c_major.set(color[0])
c_minor = StringVar(); c_minor.set(color[1])
guidata[0]['color'] = ('Major Line Color', c_major, None)
guidata[1]['color'] = ('Minor Line Color', c_minor, None)
return guidata
示例4: show_qr
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
def show_qr(path):
import platform
try:
from tkinter import Toplevel, Label
except ImportError:
raise SystemError('缺少Tkinter模块, 可使用sudo pip install Tkinter尝试安装')
try:
from PIL import ImageTk, Image
except ImportError:
raise SystemError('缺少PIL模块, 可使用sudo pip install PIL尝试安装')
system = platform.system()
if system == 'Darwin': # 如果是Mac OS X
img = Image.open(path)
img.show()
else:
root = Toplevel()
img = ImageTk.PhotoImage(
Image.open(path)
)
panel = Label(root, image=img)
panel.pack(side="bottom", fill="both", expand="yes")
root.mainloop()
示例5: ask_class_name
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
def ask_class_name():
win = Toplevel()
module_name = StringVar()
class_name = StringVar()
module_item = LabeledEntry(win)
module_item.label_text = 'Module Name'
module_item.pack()
module_item.entry_variable = module_name
class_item = LabeledEntry(win)
class_item.label_text = 'Class Name'
class_item.pack()
class_item.entry_variable = class_name
Button(win, text='OK', command=win.quit).pack()
win.protocol('WM_DELETE_WINDOW', win.quit)
win.focus_set()
win.grab_set()
win.mainloop()
win.destroy()
return module_name.get(), class_name.get()
示例6: askSpan
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
def askSpan(orient='v'):
win = Toplevel()
pxmin = LabeledEntry(win)
pxmin.pack()
pxmin.label_text = 'xmin' if orient=='v' else 'ymin'
pxmax = LabeledEntry(win)
pxmax.pack()
pxmax.label_text = 'xmax' if orient=='v' else 'ymax'
def formatter(val):
val = float(val)
val /= 100.
return '{0:0.2f}'.format(val)
alphaScale = LabeledScale(win, from_=0, to=100, name='alpha', formatter=formatter)
alphaScale.set(50.0)
alphaScale.pack()
win.protocol('WM_DELETE_WINDOW', win.quit)
win.focus_set()
win.grab_set()
win.mainloop()
xmin = pxmin.entry.get()
xmax = pxmax.entry.get()
alpha = alphaScale.get() / 100.
win.destroy()
return map(float, (xmin, xmax, alpha))
示例7: Toplevel
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
# e.g. 8-3
import sys
from tkinter import Toplevel, Button, Label
win1 = Toplevel()
win2 = Toplevel()
Button(win1, text='Spam1', command=sys.exit).pack()
Button(win2, text='Spam2', command=sys.exit).pack()
Label(text='Popups').pack()
win1.mainloop()
示例8: Overlay
# 需要导入模块: from tkinter import Toplevel [as 别名]
# 或者: from tkinter.Toplevel import mainloop [as 别名]
class Overlay(threading.Thread):
def __init__(self,
width, height,
xpos, ypos,
bgcolor, fgcolor,
fontsize, opacity,
messages, close):
threading.Thread.__init__(self, daemon=True)
self.width = width
self.height = height
self.xpos = xpos
self.ypos = ypos
self.bgcolor = bgcolor
self.fgcolor = fgcolor
self.fontsize = fontsize
self.opacity = opacity
self.messages = messages
self.close = close
username_colors = [
'#0000ff',
'#ff7f50',
'#1e90ff',
'#00ff7f',
'#9acd32',
'#00ff00',
'#ff4500',
'#ff0000',
'#daa520',
'#ff69b4',
'#5f9ea0',
'#2e8b57',
'#d2691e',
'#8a2be2',
'#b22222',
]
self.color_for = defaultdict(lambda: random.choice(username_colors))
self.start()
self.images = []
def die(self):
self.images = None
self.close.put('killme')
self.root.quit()
def run(self):
self.root = MyRoot()
self.root.lower()
self.root.iconify()
self.root.title('poetato overlay')
self.root.protocol('WM_DELETE_WINDOW', self.die)
self.app = Toplevel(self.root)
self.app.geometry("%dx%d+%d+%d" % (self.width, self.height,
self.xpos, self.ypos))
self.app.resizable(width=False, height=False)
self.app.overrideredirect(1)
self.app.minsize(width=self.width, height=self.height)
self.app.maxsize(width=self.width, height=self.height)
self.app.attributes(
'-alpha', self.opacity,
'-topmost', True,
'-disabled', True,
)
self.text = Text(self.app,
bg=self.bgcolor, fg=self.fgcolor,
wrap='word', state='disabled')
self.text.configure(font=('Helvetica', self.fontsize, 'bold'))
self.text.pack()
self.app.lift()
# tell Windows(tm) to allow clicks to pass through our overlay.
hWindow = pywintypes.HANDLE(int(self.root.frame(), 16))
exStyle = (win32con.WS_EX_LAYERED |
win32con.WS_EX_TRANSPARENT |
win32con.WS_EX_NOACTIVATE)
win32api.SetWindowLong(hWindow, win32con.GWL_EXSTYLE, exStyle)
self.app.after(100, self.update)
self.app.mainloop()
def update(self):
if self.messages.empty():
self.app.after(100, self.update)
return
msg = self.messages.get_nowait()
self.text['state'] = 'normal'
if self.text.index('end-1c') != '1.0':
self.text.insert('end', '\n')
self.text.insert('end', "{0}: ".format(msg.display_name))
emote_insertions = {}
for eid, pos in msg.emotes.items():
for p in pos:
emote_insertions[p[0]] = (msg.localemotes[eid], p[1]+1)
#.........这里部分代码省略.........