本文整理汇总了Python中tkinter.Canvas.bbox方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.bbox方法的具体用法?Python Canvas.bbox怎么用?Python Canvas.bbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.bbox方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ListDialog
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
class ListDialog(object):
def __init__ (self, master, items, message, accept_func):
self.accept_func = accept_func
self.top = Toplevel(master)
self.top.transient(master)
self.top.rowconfigure(0, weight=1)
self.top.rowconfigure(1, weight=3)
self.top.rowconfigure(2, weight=0)
self.top.columnconfigure(0, weight=1)
self.top.columnconfigure(1, weight=1)
self.top.resizable(width=True, height=True)
self.frame = Frame(self.top)
self.frame.rowconfigure(0, weight=1)
self.frame.rowconfigure(1, weight=0)
self.frame.columnconfigure(0, weight=1)
self.frame.columnconfigure(1, weight=0)
self.frame.grid(row=0, column=0, sticky=(N, S, W, E), columnspan=2)
self.canvas = Canvas(self.frame)
self.canvas.create_text(0, 0, text=message, anchor=NW)
self.canvas.grid(row=0, column=0, sticky=(N, W, S, E))
self.vscroll = Scrollbar(self.frame, command=self.canvas.yview)
self.vscroll.grid(row=0, column=1, sticky=(N, S))
self.canvas['yscrollcommand'] = self.vscroll.set
self.hscroll = Scrollbar(self.frame, command=self.canvas.xview, orient=HORIZONTAL)
self.hscroll.grid(row=1, column=0, sticky=(W, E), columnspan=2)
self.canvas['xscrollcommand'] = self.hscroll.set
self.canvas['scrollregion'] = self.canvas.bbox('all')
self.canvas.bind('<Button-4>', self.scroll)
self.canvas.bind('<Button-5>', self.scroll)
self.canvas.bind('<MouseWheel>', self.scroll)
self.view = NameView(self.top, sorted(items))
self.view.widget.grid(row=1, column=0, columnspan=2, sticky=(N, W, E, S))
self.delbutton = Button(self.top, text='Ok', command=self.accept )
self.cancelbutton = Button(self.top, text='Cancel', command=self.cancel)
self.delbutton.grid(row=2, column=0)
self.cancelbutton.grid(row=2, column=1)
self.view.widget.focus_set()
def accept(self):
self.accept_func(self.view.selection())
self.top.destroy()
def cancel(self):
self.result = None
self.top.destroy()
def scroll(self, event):
if event.num == 4 or event.delta > 0:
self.canvas.yview(SCROLL, -1, UNITS)
elif event.num == 5 or event.delta < 0:
self.canvas.yview(SCROLL, 1, UNITS)
示例2: RadiobuttonEntry
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
class RadiobuttonEntry(ttk.Frame):
"""State entry for all DMs, and controls for adding the infeasibles.
Uses a set of RadioButtonSeries elements.
"""
def __init__(self, master, conflict):
"""Initialize the widget."""
ttk.Frame.__init__(self, master)
self.conflict = conflict
self.dmLookup = {dm.name: dm for dm in self.conflict.decisionMakers}
dmNames = tuple(self.dmLookup.keys())
self.activeDMname = StringVar(value=dmNames[0])
self.activeDM = self.dmLookup[dmNames[0]]
dmSelLabel = ttk.Label(self, text="Decision Maker")
dmSelLabel.grid(column=0, row=0)
self.dmSelector = ttk.Combobox(self, textvariable=self.activeDMname,
values=dmNames, state='readonly')
self.dmSelector.grid(column=1, row=0, sticky=NSEW)
self.dmSelector.bind('<<ComboboxSelected>>', self.dmSel)
self.rbeCanvas = Canvas(self)
self.rdBtnFrame = ttk.Frame(self.rbeCanvas)
self.scrollY = ttk.Scrollbar(self, orient=VERTICAL,
command=self.rbeCanvas.yview)
self.rbeCanvas.grid(column=0, row=1, columnspan=2, sticky=NSEW)
self.scrollY.grid(column=2, row=1, sticky=NSEW)
self.rbeCanvas.configure(yscrollcommand=self.scrollY.set)
self.canvWindow = self.rbeCanvas.create_window(
(0, 0), window=self.rdBtnFrame, anchor='nw')
self.rowconfigure(1, weight=1)
self.entryText = StringVar(value='')
vcmd = self.register(self.onValidate)
self.entryBx = ttk.Entry(self, textvariable=self.entryText,
validate="key",
validatecommand=(vcmd, '%S', '%P'))
self.entryBx.grid(column=0, row=2, columnspan=2, sticky=NSEW)
self.entryBx.bind('<Return>', self.generateAdd)
self.warnText = StringVar(value='')
self.addBtn = ttk.Button(self, text='Remove as Misperceived Condition',
command=self.generateAdd)
self.mutExBtn = ttk.Button(self,
text='Perceived as Mutually Exclusive',
command=self.generateMutEx)
self.warnLab = ttk.Label(self, textvariable=self.warnText)
self.warnLab.grid(column=0, row=3, sticky=NSEW)
self.addBtn.grid(column=0, row=4, columnspan=2, sticky=NSEW)
self.mutExBtn.grid(column=0, row=5, columnspan=2, sticky=NSEW)
self.reloadOpts()
def resize(self, event=None):
"""Resize the scroll region of the main canvas element."""
self.rbeCanvas.configure(scrollregion=self.rbeCanvas.bbox("all"))
self.rbeCanvas["width"] = self.rbeCanvas.bbox("all")[2]
def generateAdd(self, *args):
"""Prompt response to addition of an infeasible state."""
self.event_generate('<<addMisperceived>>')
def generateMutEx(self, *args):
"""Prompt response to addition of a mutually exclusive set."""
self.event_generate('<<AddMutEx>>')
def reloadOpts(self):
"""Reload all options for all DMs."""
self.rbeCanvas.delete(self.canvWindow)
self.rdBtnFrame.destroy()
self.rdBtnFrame = ttk.Frame(self.rbeCanvas)
self.canvWindow = self.rbeCanvas.create_window(
(0, 0), window=self.rdBtnFrame, anchor='nw')
self.rdBtnFrame.bind('<<RdBtnChg>>', self.rdBtnChgCmd)
self.rdBtnFrame.bind("<Configure>", self.resize)
self.rdBtnSrs = []
self.stringVarList = []
for x, dm in enumerate(self.conflict.decisionMakers):
a = RadiobuttonSeries(self.rdBtnFrame, dm)
self.rdBtnSrs.append(a)
a.setOpts(dm.options)
a.grid(column=0, row=int(x), sticky=NSEW)
self.stringVarList += a.stringVarList
self.rdBtnChgCmd()
def setStates(self, dashOne):
"""Change the condition selected on the radio buttons."""
if len(dashOne) != len(self.stringVarList):
raise Exception('string length does not match number '
#.........这里部分代码省略.........
示例3: mainGUI
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
class mainGUI(Frame, bootloader, GuiController):
""" Contains the main view for the application """
def __init__(self):
""" Create the initial application GUI environment (tool bars, and other static elements) """
Frame.__init__(self, self.root)
self.thread_entry_field = '' # Hold both search string, and drives autoRefresh logic
self.menuBar = Menu()
self.fileMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="File", menu=self.fileMenu, underline=1)
self.fileMenu.add_command(label="Quit", command=self.root.destroy, underline=1)
self.optionsMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="Options", menu=self.optionsMenu)
self.optionsMenu.add_command(label="Settings", command=self.editSettings, underline=1)
self.helpMenu = Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label="Help", menu=self.helpMenu)
self.helpMenu.add_command(label="Help", command=self.program_help, underline=1)
self.helpMenu.add_command(label="About", command=self.program_about, underline=1)
self.master.config(menu=self.menuBar)
self.topFrame = Frame()
self.thread_entry_box = Entry(self.topFrame)
self.thread_entry_box.insert(0, self.DEFAULT_THREAD_TEXT)
self.thread_entry_box.bind('<Return>', lambda event: self.add_thread_GUI())
# Bind needs to send the event to the handler
self.thread_entry_box.pack(side='left', fill='x', expand='True', padx=5)
self.add_thread_btn = Button(self.topFrame)
self.add_thread_btn['text'] = 'Add New Thread'
self.add_thread_btn['command'] = lambda: self.add_thread_GUI()
self.add_thread_btn.pack(side='left', padx=0)
self.topFrame.pack(fill='x')
self.create_thread_frame()
def create_thread_frame(self):
""" Sets up the main thread frame (where the magic happens) """
# Sets up frame
self.thread_list_canvas = Canvas(self.root, borderwidth=0)
self.thread_list_frame = Frame(self.thread_list_canvas)
# Creates scroll bar
self.vsb = Scrollbar(self.root, orient="vertical", command=self.thread_list_canvas.yview)
self.thread_list_canvas.configure(yscrollcommand=self.vsb.set)
self.vsb.pack(side="right", fill="y")
self.hsb = Scrollbar(self.root, orient="horizontal", command=self.thread_list_canvas.xview)
self.thread_list_canvas.configure(xscrollcommand=self.hsb.set)
self.hsb.pack(side="bottom", fill="x")
# Packs frame
self.thread_list_canvas.pack(side="left", fill="both", expand=True)
self.thread_list_canvas.create_window((4, 4), window=self.thread_list_frame, anchor="nw", tags="self.frame")
self.thread_list_frame.bind("<Configure>", self.OnFrameConfigure)
self.create_thread_list_box()
def OnFrameConfigure(self, event):
"""Reset the scroll region to encompass the inner frame"""
self.thread_list_canvas.configure(scrollregion=self.thread_list_canvas.bbox("all"))
# noinspection PyAttributeOutsideInit
def create_thread_list_box(self):
""" Creates the message list box for the create method """
def hover_on(widget):
widget['fg'] = 'dark blue'
# widget['underline'] = True
def hover_off(widget):
widget['fg'] = 'black'
# widget['underline'] = False
for individual_thread in self.MESSAGE_THREADS: # Fetch Message List from model
if individual_thread.is_valid_thread():
self.bg_color = 'green'
else:
self.bg_color = 'red'
self.individual_thread_frame = Frame(self.thread_list_frame,
bg=self.bg_color) # Create frame for each thread
rowToInsertAt = self.MESSAGE_THREADS.index(individual_thread)
self.text_color = 'black'
self.threadText = Label(self.individual_thread_frame, bg=self.bg_color, fg=self.text_color)
self.threadText['text'] = "[ Thread #: " + individual_thread.threadId + " ]"
self.threadText.bind("<Enter>", lambda event, text=self.threadText: hover_on(text))
self.threadText.bind("<Leave>", lambda event, text=self.threadText: hover_off(text))
self.threadText.bind("<Button-1>",
lambda event, thread_in=individual_thread: self.open_in_web_browser(thread_in))
self.threadText.grid(column=0, row=0, sticky='w', padx=0)
#.........这里部分代码省略.........
示例4: GraphView
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
#.........这里部分代码省略.........
for d in self._data:
d.append()
if self._data[pos].size() > 1:
self._write_prev_records()
self._data[pos].put_value(value)
graph_w = self._win_size[0] - self._graph_x;
count = int(graph_w / GraphView.POINT_MARGIN + 1)
for d in self._data:
d.shrink(count)
def _write_prev_records(self):
write = ','.join((str(d.get_value(-2)) for d in self._data)) + '\n'
self._file.write(write)
self._file.flush()
def _refresh(self):
self._redraw_graph()
self._tk.after(16, self._refresh)
def _full_redraw(self):
self._canvas.delete("all")
bounding_box = self._redraw_data_labels()
self._graph_rect = 0, 0, self._win_size[0], bounding_box[1]
self._redraw_y_labels()
for v in self._data_view:
v.clear_lines();
self._redraw_graph()
def _redraw_data_labels(self):
top = self._win_size[1]
x = GraphView._DATA_LABEL_PADDING
for l, c in zip(self._labels, self._colors):
t = self._canvas.create_text(x,
self._win_size[1] - GraphView._DATA_LABEL_PADDING,
anchor = tkinter.SW, fill = c, font = config.FONT,
text = '-' + l)
bounding_box = self._canvas.bbox(t)
top = min(top, bounding_box[1])
x = bounding_box[2] + GraphView._DATA_LABEL_PADDING
return 0, top, x, self._win_size[1]
def _redraw_y_labels(self):
height = self._graph_rect[3] - self._graph_rect[1] \
- GraphView.WIN_PADDING_Y * 2
count = max(int(height / 50), 2)
labels = []
max_label_size = 0
longest_label = None
longest_label_i = None
for i in range(count):
ratio = i / (count - 1)
value = self._max - self._diff * ratio
value_label = ("%.2f" % value) if value % 1 != 0 else str(value)
labels.append(value_label)
if len(value_label) > max_label_size:
max_label_size = len(value_label)
longest_label = value_label
longest_label_i = i
label_id = self._canvas.create_text(0, height * (longest_label_i \
/ (count - 1)) + GraphView.WIN_PADDING_Y,
anchor = tkinter.W, fill = config.COL_GREY_100,
font = config.FONT, text = longest_label)
bounding_box = self._canvas.bbox(label_id)
width = bounding_box[2] - bounding_box[0]
self._graph_x = width + GraphView.POINT_MARGIN
for i in range(count):
ratio = i / (count - 1)
y = height * ratio + GraphView.WIN_PADDING_Y
if i != longest_label_i:
self._canvas.create_text(width, y, anchor = tkinter.E,
fill = config.COL_GREY_100, font = config.FONT,
text = labels[i])
self._canvas.create_line(self._graph_x, y, self._graph_rect[2], y,
fill = config.COL_GREY_700)
def _redraw_graph(self):
graph_h = self._graph_rect[3] - GraphView.WIN_PADDING_Y * 2
for d, v in zip(self._data, self._data_view):
v.populate(d.get_values(), self._max, self._diff, self._graph_x,
graph_h)
v.draw(self._canvas)
def _get_auto_colors(self, size) -> list:
product = GraphView._COLOR_REPO[:min(size, len(GraphView._COLOR_REPO))]
while len(product) < size:
product.append("#%06x" % random.randrange(0xFFFFFF))
return product
_LABEL_SIZE = 10
_DATA_LABEL_PADDING = 8
_MSG_SIZE = 6
_MSG_TYPE_INT = 0
_MSG_TYPE_FLOAT = 1
_COLOR_REPO = ["#F44336", "#4CAF50", "#2196F3", "#FFEB3B", "#607D8B",
"#9C27B0", "#009688", "#673AB7", "#795548"]
示例5: GUI
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
class GUI():
"""
Method gets a Tk instance (master) and a model instance implemented with nengo.
It then creates a GUI with the polts that where specified in create_plot(...).
"""
def __init__(self, master, model):
self.f = 0
master.rowconfigure(0, weight=1)
master.columnconfigure(0, weight=1)
self.frame = tk.Frame(master)
self.frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
self.frame.grid(sticky=NSEW)
self.frame.rowconfigure(0, weight=1)
self.frame.columnconfigure(0, weight=1)
self.scroll_canvas = Canvas(self.frame)
self.scroll_canvas.grid(row=0, column=0, sticky=NSEW)
xScrollbar = Scrollbar(self.frame, orient=HORIZONTAL)
yScrollbar = Scrollbar(self.frame)
xScrollbar.grid(row=1, column=0, sticky=EW)
yScrollbar.grid(row=0, column=1, sticky=NS)
self.scroll_canvas.config(xscrollcommand=xScrollbar.set)
xScrollbar.config(command=self.scroll_canvas.xview)
self.scroll_canvas.config(yscrollcommand=yScrollbar.set)
yScrollbar.config(command=self.scroll_canvas.yview)
self.create_plot(model)
self.figure_canvas = FigureCanvasTkAgg(self.f, master=self.scroll_canvas)
self.canvas = self.figure_canvas.get_tk_widget()
self.canvas.pack(side=tk.TOP, fill=tk.BOTH, padx=5, pady=5, expand=1)
self.scroll_canvas.create_window(0, 0, window=self.canvas)
self.scroll_canvas.config(scrollregion=self.scroll_canvas.bbox(ALL))
self.figure_canvas.show()
self.toolbar = NavigationToolbar2TkAgg(self.figure_canvas, self.scroll_canvas)
self.toolbar.pack()
self.toolbar.update()
"""
Adds the specified plots to the figure displayed in the GUI. It gets a model instance implemented with nengo
"""
def create_plot(self, model):
self.f = Figure(figsize=(16, 9), dpi=80)
"""
Example plot which plots the integrators back connection, its input, its real value and the real robot goal angle
"""
self.ax00 = self.f.add_axes((.2, .2, .6, .6), axisbg=(.75, .75, .75), frameon=True)
self.ax00.plot(model.sim.trange(), model.sim.data[model.integrator_probe], label = 'Integrator')
self.ax00.plot(model.sim.trange(), model.sim.data[model.integrator_connection_probe], label = 'Con')
self.ax00.plot(model.sim.trange(), model.sim.data[model.integrator_self_connection_probe], label = 'Self Con')
self.ax00.plot(model.sim.trange(), model.sim.data[model.robot_goal_neuron_probe][:, 2], label = 'Real')
self.ax00.legend()
示例6: TKinterDisplay
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
#.........这里部分代码省略.........
def renderTextInId(self, tagTocentreOn, tagsToAddTo, content, funcContent):
id1tuple = self.__getCoords(tagTocentreOn)
x1 = id1tuple[0] + ((id1tuple[2] - id1tuple[0]) / 2)
y1 = id1tuple[1] + ((id1tuple[3] - id1tuple[1]) / 2)
txt = self.__renderText(x1, y1, (id1tuple[2] - id1tuple[0]), content, tagsToAddTo)
def handler(event, self=self, content=funcContent):
return self.__eventOnClick(event, content)
self.localCanvas.tag_bind(txt, "<ButtonRelease-1>", handler)
return txt
@abstractmethod
def move(self, tag, xamount, yamount):
self.localCanvas.move(tag, xamount, yamount)
@abstractmethod
def runDisplay(self):
self.localCanvas.mainloop()
def __hideId(self, objectId):
self.localCanvas.itemconfigure(objectId, state="hidden")
pass
def __showId(self, objectId):
self.localCanvas.itemconfigure(objectId, state="normal")
pass
def __sampleDraw(self):
self.localCanvas.create_oval(0, 0, 0, 0, width=0)
def __renderText(self, x, y, width, content, tag):
val = self.localCanvas.create_text(x, y, width=width, text=content, tags=tag, justify="center", font="Helvetica 8 bold", anchor="center")
self.localCanvas.tag_raise(val)
return val
def __drawLine(self, x1, y1, x2, y2, tags=None, colour="black"):
line = self.localCanvas.create_line(x1, y1, x2, y2, tags=tags, width=self.lineThickness, arrow="first", arrowshape=(16,20,6),fill=colour, smooth=True)
self.localCanvas.tag_lower(line)
return # line
def __remove(self, num):
self.localCanvas.delete(num)
def __getCoords(self, ident):
return self.localCanvas.coords(ident)
def __eventOnFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
assert self.localCanvas
coord_tuple = self.localCanvas.bbox("all")
if not coord_tuple:
logging.error("Frame reconfigure error on coordinate acquire.")
else:
reconWidth = coord_tuple[2] - coord_tuple[0]
reconHeight = coord_tuple[3] - coord_tuple[1]
self.localCanvas.configure(width=reconWidth)
self.localCanvas.configure(height=reconHeight)
self.localCanvas.configure(scrollregion=self.localCanvas.bbox("all"))
self.localCanvas.update_idletasks()
def __eventOnClick(self, event, content):
self.__createWindowOnId(self.localCanvas.find_withtag(CURRENT), content)
def __createWindowOnId(self, itemId, content):
if self.currentlyRenderedWindow != None:
self.currentlyRenderedWindow()
# self.__remove(self.currentlyRenderedWindow)
idtuple = self.localCanvas.coords(itemId)
if idtuple:
x = idtuple[0]
y = idtuple[1]
frm = Frame(self.localCanvas)
frm.grid(row=0, column=0)
canv = Canvas(frm)
vscroll = Scrollbar(frm, orient="vertical", command=canv.yview)
vscroll.grid(row=0, column=1, sticky=N + S)
canv.grid(row=0, column=0)
canv["yscrollcommand"] = vscroll.set
aframe = Frame(canv)
aframe.grid(row=0, column=0)
Label(aframe, text=content, anchor="center", background="#CCFFCC", borderwidth=6, relief="ridge", justify="left").grid(row=1, column=0)
canvWindow = canv.create_window(x, y, window=aframe)
canv.coords(canvWindow, x, y)
self.localCanvas.update_idletasks()
canv["scrollregion"] = canv.bbox("all")
def destroyAll():
self.__remove(canvWindow)
canv.destroy()
aframe.destroy()
vscroll.destroy()
frm.destroy()
self.currentlyRenderedWindow = destroyAll
Button(frm, text="Close", command=lambda : destroyAll()).grid(row=2, column=0)
示例7: RadiobuttonEntry
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
class RadiobuttonEntry(ttk.Frame):
"""State entry for the entire conflict. A set of RadioButtonSeries."""
def __init__(self, master, conflict):
"""State entry widget for the entire conflict."""
ttk.Frame.__init__(self, master)
self.conflict = conflict
self.rbeCanvas = Canvas(self)
self.rdBtnFrame = ttk.Frame(self.rbeCanvas)
self.scrollY = ttk.Scrollbar(self, orient=VERTICAL,
command=self.rbeCanvas.yview)
self.rbeCanvas.grid(column=0, row=0, columnspan=2, sticky=NSEW)
self.scrollY.grid(column=2, row=0, sticky=NSEW)
self.rbeCanvas.configure(yscrollcommand=self.scrollY.set)
self.canvWindow = self.rbeCanvas.create_window((0, 0),
window=self.rdBtnFrame,
anchor='nw')
self.rowconfigure(0, weight=1)
self.entryText = StringVar(value='')
vcmd = self.register(self.onValidate)
self.entryBx = ttk.Entry(self, textvariable=self.entryText,
validate="key",
validatecommand=(vcmd, '%S', '%P'))
self.entryBx.grid(column=0, row=1, sticky=NSEW)
self.entryBx.bind('<Return>', self.generateAdd)
self.warnText = StringVar(value='')
self.warnLab = ttk.Label(self, textvariable=self.warnText, width=18)
self.warnLab.grid(column=1, row=1, sticky=NSEW)
self.codeText = StringVar(value='')
vcmd2 = self.register(self.onValidate2)
self.codeBx = ttk.Entry(self, textvariable=self.codeText,
validate="key",
validatecommand=(vcmd2, '%S', '%P'))
self.codeBx.grid(column=0, row=2, sticky=NSEW)
self.codeBx.bind('<Return>', self.generateAdd)
self.warnText2 = StringVar(value='')
self.warnLab2 = ttk.Label(self, textvariable=self.warnText2)
self.warnLab2.grid(column=1, row=2, sticky=NSEW)
self.addBtn = ttk.Button(self, text='Add as Prefered State',
command=self.generateAdd)
self.stageBtn = ttk.Button(self, text='Add to Staging',
command=self.generateStage)
self.addBtn.grid(column=0, row=4, columnspan=2, sticky=NSEW)
self.stageBtn.grid(column=0, row=5, columnspan=2, sticky=NSEW)
self.isDisabled = False
self.columnconfigure(0, weight=1)
self.reloadOpts()
self.regexValidChars = re.compile(r'^[-\d, fi]*$')
self.regexStatesIf = re.compile(r'^ *(-)?(\d+) *iff? *(-)?(\d+) *$')
self.regexStates = re.compile(r' *(-)?(\d+) *')
self.hasValidIf = False
def resize(self, event=None):
"""Adjust the canvas widget if the window is resized."""
self.rbeCanvas.configure(scrollregion=self.rbeCanvas.bbox("all"))
self.rbeCanvas["width"] = self.rbeCanvas.bbox("all")[2]
def generateAdd(self, event=None):
"""Generate event if a preference is added."""
self.event_generate('<<AddPref>>')
def generateStage(self, event=None):
"""Generate event if a preference is staged."""
self.event_generate('<<StagePref>>')
def reloadOpts(self):
"""Reload options for all decision makers."""
self.rbeCanvas.delete(self.canvWindow)
self.rdBtnFrame.destroy()
self.rdBtnFrame = ttk.Frame(self.rbeCanvas)
self.canvWindow = self.rbeCanvas.create_window((0, 0),
window=self.rdBtnFrame,
anchor='nw')
self.rdBtnFrame.bind('<<RdBtnChg>>', self.rdBtnChgCmd)
self.rdBtnFrame.bind("<Configure>", self.resize)
self.rdBtnSrs = []
self.stringVarList = []
for x, dm in enumerate(self.conflict.decisionMakers):
a = RadiobuttonSeries(self.rdBtnFrame, dm)
self.rdBtnSrs.append(a)
a.setOpts(dm.options)
#.........这里部分代码省略.........
示例8: __createWindowOnId
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import bbox [as 别名]
def __createWindowOnId(self, itemId, content):
if self.currentlyRenderedWindow != None:
self.currentlyRenderedWindow()
# self.__remove(self.currentlyRenderedWindow)
idtuple = self.localCanvas.coords(itemId)
if idtuple:
x = idtuple[0]
y = idtuple[1]
frm = Frame(self.localCanvas)
frm.grid(row=0, column=0)
canv = Canvas(frm)
vscroll = Scrollbar(frm, orient="vertical", command=canv.yview)
vscroll.grid(row=0, column=1, sticky=N + S)
canv.grid(row=0, column=0)
canv["yscrollcommand"] = vscroll.set
aframe = Frame(canv)
aframe.grid(row=0, column=0)
Label(aframe, text=content, anchor="center", background="#CCFFCC", borderwidth=6, relief="ridge", justify="left").grid(row=1, column=0)
canvWindow = canv.create_window(x, y, window=aframe)
canv.coords(canvWindow, x, y)
self.localCanvas.update_idletasks()
canv["scrollregion"] = canv.bbox("all")
def destroyAll():
self.__remove(canvWindow)
canv.destroy()
aframe.destroy()
vscroll.destroy()
frm.destroy()
self.currentlyRenderedWindow = destroyAll
Button(frm, text="Close", command=lambda : destroyAll()).grid(row=2, column=0)