本文整理汇总了Python中Tkinter.Frame.mainloop方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.mainloop方法的具体用法?Python Frame.mainloop怎么用?Python Frame.mainloop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.mainloop方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: showDialog
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import mainloop [as 别名]
def showDialog():
win = Frame(padx=10, pady=10)
win.pack()
Label(win, text="Hallo Bruce!").pack(side=TOP)
Button(win, text="Exit 0", command=(lambda: exitProgram(0))).pack(side=LEFT)
Button(win, text="Exit 1", command=(lambda: exitProgram(1))).pack(side=RIGHT)
win.mainloop()
示例2: _test
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import mainloop [as 别名]
def _test():
from Tkinter import Text
from Tkconstants import TOP, BOTTOM, X
b = Frame()
c = Text(b)
c.pack(side=TOP)
a = MultiStatusBar(b)
a.set_label("one", "hello")
a.set_label("two", "world")
a.pack(side=BOTTOM, fill=X)
b.pack()
b.mainloop()
示例3: _multistatus_bar
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import mainloop [as 别名]
def _multistatus_bar(parent):
root = Tk()
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
root.geometry("+%d+%d" %(x, y + 150))
root.title("Test multistatus bar")
frame = Frame(root)
text = Text(frame)
text.pack()
msb = MultiStatusBar(frame)
msb.set_label("one", "hello")
msb.set_label("two", "world")
msb.pack(side=BOTTOM, fill=X)
def change():
msb.set_label("one", "foo")
msb.set_label("two", "bar")
button = Button(root, text="Update status", command=change)
button.pack(side=BOTTOM)
frame.pack()
frame.mainloop()
root.mainloop()
示例4: update_status
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import mainloop [as 别名]
g_coord = self.g_bubbles_x[i],self.g_bubbles_y[i],self.g_bubbles_x[i]+BUBBLES_SIZE,self.g_bubbles_y[i]+BUBBLES_SIZE
self.g_bubbles_id.append(self.canvas.create_oval(g_coord,fill=''))
def update_status(self):
bPtr = 0
angle = 0.0
while True:
for i in range(self.number_of_gbubbles):
self.canvas.move(self.g_bubbles_id[i],random.randint(-10,10),random.randint(-10,10))
self.canvas.after_idle(self.update)
tkimage = ImageTk.PhotoImage(self.image.rotate(angle))
cp1_obj = self.canvas.create_image(100,100,image = tkimage)
cp2_obj = self.canvas.create_image(250,100,image = tkimage)
yield
self.canvas.delete(cp1_obj)
self.canvas.delete(cp2_obj)
angle+=4
angle%=360.0
master_frame = Frame()
g = dk_gui(master_frame)
#g.update_status()
master_frame.mainloop()
示例5: Form
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import mainloop [as 别名]
#.........这里部分代码省略.........
self._ctrl.update_idletasks()
@property
def top(self):
return self._geometry().top
@top.setter
def top(self, value):
self._ctrl.geometry("+{}+{}".format(self.left, value))
self._ctrl.update_idletasks()
@property
def height(self):
if self.visible:
return self._geometry().height
else:
return self._hidden_height
@height.setter
def height(self, value):
self._hidden_height = value
self._ctrl.geometry("{}x{}".format(self.width, value))
self._ctrl.update_idletasks()
@property
def caption(self):
return self._ctrl.title()
@caption.setter
def caption(self, value):
self._ctrl.title(value)
@property
def resizable(self):
return self._ctrl.resizable() != '0 0'
@resizable.setter
def resizable(self, value):
if not isinstance(value, bool):
raise Exception('resizable value must be a bool')
self._ctrl.resizable(int(value),int(value))
self._ctrl.update_idletasks()
@property
def form_type(self):
if os.name == 'nt':
return int(self._ctrl.attributes('-toolwindow'))
else:
return SINGLE
@form_type.setter
def form_type(self, value):
if os.name != 'nt':
return
if value not in [SINGLE, TOOLWIN]:
raise Exception('Invalid form type')
self._ctrl.attributes('-toolwindow', value)
@property
def icon(self):
return self._icon
@icon.setter
def icon(self, value):
self._icon = value
self._ctrl.wm_iconbitmap(value)
@property
def visible(self):
return self._ctrl.state() != 'withdrawn'
@visible.setter
def visible(self, value):
if self.visible == value:
return
elif value:
self.show()
else:
self.hide()
def show(self):
self._ctrl.update()
self._ctrl.deiconify()
if self == Form._main_form:
self._frame.mainloop()
def hide(self):
self._ctrl.withdraw()
def close(self):
self._on_close_handler()
def show_modal(self):
self.show()
if self == Form._main_form:
return
self._ctrl.grab_set()
for form in Form._active_forms:
if form != self:
form._ctrl.wait_window(self._ctrl)
示例6: MainWindow
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import mainloop [as 别名]
class MainWindow(object):
"""Main window that allows users to draw a digit and classify it.
"""
def __init__(self, model):
"""Sets up the user interface.
Args:
model: The trained model for classifying digits.
"""
self.model_ = model
self.main_window_ = Tk()
self.main_frame_ = Frame(self.main_window_)
self.canvas_ = Canvas(self.main_window_, width=WIDTH, height=HEIGHT,
bg="black")
self.canvas_.grid(row=0)
self.img_ = Image.new(mode="L", size=(WIDTH, HEIGHT), color="black")
self.img_draw_ = ImageDraw.Draw(self.img_)
self.canvas_.bind("<B1-Motion>", self.OnMouseDragged)
self.canvas_.bind("<ButtonRelease-1>", self.OnMouseReleased)
self.last_x_ = None
self.last_y_ = None
self.line_width_ = 3
self.classify_ = Button(self.main_window_, text="Classify",
command=self.Classify)
self.classify_.grid(row=1, sticky=N+S+E+W)
self.clear_ = Button(self.main_window_, text="Clear",
command=self.Clear)
self.clear_.grid(row=2, sticky=N+S+E+W)
self.main_frame_.place(relx=0.5, rely=0.5, anchor=CENTER)
def OnMouseDragged(self, event):
"""Handles drawing on the canvas.
Args:
event: the data associated with the drag event
"""
if self.last_x_ is not None and self.last_y_ is not None:
self.canvas_.create_line(self.last_x_, self.last_y_, event.x,
event.y, fill="white",
width=self.line_width_)
self.img_draw_.line((self.last_x_-self.line_width_, self.last_y_-self.line_width_, event.x-self.line_width_, event.y-self.line_width_),
fill="white", width=self.line_width_)
self.last_x_, self.last_y_ = event.x, event.y
def OnMouseReleased(self, event):
"""Handles when mouse button released on canvas.
"""
self.last_x_ = None
self.last_y_ = None
def Classify(self):
"""Classifies the digit drawn on the canvas.
"""
print "Classifying..."
pixels = np.zeros([1,WIDTH*HEIGHT], dtype=np.float32)
for y in range(HEIGHT):
for x in range(WIDTH):
pixels[0][y*HEIGHT + x] = (0 if self.img_.getpixel((x, y)) == 0
else 1)
prediction = self.model_.Predict(pixels)
self.img_.save("test.png", "png")
tkMessageBox.showinfo("Classification Result",
"The classifier believes you drew a %d"
%(prediction))
def Clear(self):
"""Clears the digit drawn on the canvas.
"""
self.canvas_.delete("all")
self.img_ = Image.new(mode="L", size=(WIDTH, HEIGHT), color="black")
self.img_draw_ = ImageDraw.Draw(self.img_)
self.last_x_, self.last_y_ = None, None
def Show(self):
"""Shows the main frame.
"""
self.main_frame_.mainloop()