本文整理汇总了Python中tkinter.mainloop函数的典型用法代码示例。如果您正苦于以下问题:Python mainloop函数的具体用法?Python mainloop怎么用?Python mainloop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mainloop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self.main_window = tkinter.Tk()
self.top_frame = tkinter.Frame()
self.bottom_frame = tkinter.Frame()
self.prompt_label = tkinter.Label(self.top_frame, text='Enter employee ID:')
self.employee_entry = tkinter.Entry(self.top_frame, width=10)
self.prompt_label.pack(side='left')
self.employee_entry.pack(side='left')
self.add_button = tkinter.Button(self.bottom_frame,text='Add', command=self.employee_add)
self.edit_button = tkinter.Button(self.bottom_frame, text='Edit', command=self.employee_edit)
self.payroll_button = tkinter.Button(self.bottom_frame, text='Payroll', command=self.employee_payroll)
self.add_button.pack(side='left')
self.edit_button.pack(side='left')
self.payroll_button.pack(side='left')
self.top_frame.pack()
self.bottom_frame.pack()
tkinter.mainloop()
示例2: code_list
def code_list():
var2 = tk.StringVar()
for each in codes.values():
import os
if each[1] == 0:
my_file = open("Slist.txt", "a")
my_file.write("\n")
my_file.write(each[0])
my_file.close()
each[1] = 2
continue
def code_print():
admin = var2.get()
if admin == "-1":
import os
os.startfile("C:/Users/Tiger/Desktop/Login Files/Slist.txt", "print")
class PrintSC:
LARGE_FONT = ("Verdana", 39)
label6 = tk.Label(text=" ", font=LARGE_FONT)
label6.pack()
label5 = tk.Label(text="Enter Admin Code to print", font=LARGE_FONT)
label5.pack(pady=10, padx=10)
entry2 = tk.Entry(textvariable=var2, width=35, font=LARGE_FONT)
entry2.pack()
button3 = tk.Button(text="Enter", command=code_print, width=10, font=LARGE_FONT)
button3.pack()
button4 = tk.Button(text="Exit", command=code_end, width=10, font=LARGE_FONT)
button4.pack()
tk.mainloop()
示例3: main
def main():
class DownloadTaskHandler(Thread):
def run(self):
# 模拟下载任务需要花费10秒钟时间
time.sleep(10)
tkinter.messagebox.showinfo('提示', '下载完成!')
# 启用下载按钮
button1.config(state=tkinter.NORMAL)
def download():
# 禁用下载按钮
button1.config(state=tkinter.DISABLED)
# 通过daemon参数将线程设置为守护线程(主程序退出就不再保留执行)
DownloadTaskHandler(daemon=True).start()
def show_about():
tkinter.messagebox.showinfo('关于', '作者: 骆昊(v1.0)')
top = tkinter.Tk()
top.title('单线程')
top.geometry('200x150')
top.wm_attributes('-topmost', 1)
panel = tkinter.Frame(top)
button1 = tkinter.Button(panel, text='下载', command=download)
button1.pack(side='left')
button2 = tkinter.Button(panel, text='关于', command=show_about)
button2.pack(side='right')
panel.pack(side='bottom')
tkinter.mainloop()
示例4: __init__
def __init__(self):
#create the main window widget
self.main_window=tkinter.Tk()
#Create a Button Widget. The text
#Should appear on the face of the button. The
#do_something method should execute when the
#user click the Button.
self.my_button1=tkinter.Button(self.main_window, text='10 Digit ISBN Check', command=self.check_digit_10)
self.my_button2=tkinter.Button(self.main_window, text='13 Digit ISBN Check', command=self.check_digit_13)
self.my_button3=tkinter.Button(self.main_window, text='Convert 10 to 13 ISBN', command=self.convert_10_to_13)
self.my_button4=tkinter.Button(self.main_window, text='Convert 13 to 10 ISBN', command=self.convert_13_to_10)
#Create a Quit Button. When this button is clicked the root
#widget's destroy method is called.
#(The main_window variable references the root widget, so the
#callback function is self.main_window.destroy.)
self.quit_button=tkinter.Button(self.main_window, text='Quit', command=self.main_window.destroy)
#pack the buttons
self.my_button1.pack()
self.my_button2.pack()
self.my_button3.pack()
self.my_button4.pack()
self.quit_button.pack()
#Enter the tkinter main loop
tkinter.mainloop()
示例5: __init__
def __init__(self):
'''
Constructor
'''
self.main_window = tkinter.Tk()
self.top_frame = tkinter.Frame(self.main_window)
self.mid_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
self.name_label = tkinter.Label(self.top_frame, text="Name:")
self.name_entry = tkinter.Entry(self.top_frame, width=10)
self.name_label.pack(side="left")
self.name_entry.pack(side="left")
# create a variable to store the greeting output and a label to update the greeting message in the window
self.output_greeting = tkinter.StringVar()
self.the_greeting = tkinter.Label(self.mid_frame, textvariable=self.output_greeting)
self.the_greeting.pack(side="left")
self.greeting_button = tkinter.Button(self.bottom_frame, text="Greet!", command=self.greet)
self.exit_button = tkinter.Button(self.bottom_frame, text="Exit!", command=self.main_window.destroy)
self.greeting_button.pack(side="top")
self.exit_button.pack(side="top")
self.top_frame.pack()
self.mid_frame.pack()
self.bottom_frame.pack()
tkinter.mainloop()
示例6: mb_to_tkinter
def mb_to_tkinter(maxiters, xmin, xmax, ymin, ymax, imgwd, imght):
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
array_ = get_mandelbrot(maxiters, xmin, xmax, ymin, ymax, imgwd, imght)
window = tk.Tk()
canvas = tk.Canvas(window, width=imgwd, height=imght, bg="#000000")
img = tk.PhotoImage(width=imgwd, height=imght)
canvas.create_image((0, 0), image=img, state="normal", anchor=tk.NW)
i = 0
for y in range(imght):
for x in range(imgwd):
n = array_[i]
color = escapeval_to_color(n, maxiters)
r = hex(color[0])[2:].zfill(2)
g = hex(color[1])[2:].zfill(2)
b = hex(color[2])[2:].zfill(2)
img.put("#" + r + g + b, (x, y))
i += 1
println("mb_to_tkinter %s" % time.asctime())
canvas.pack()
tk.mainloop()
示例7: trial
def trial(do_box, do_hull, n):
print('generating n=' + str(n) + ' points...')
points = random_points(n)
hull = []
if do_box:
print('bounding box...')
start = time.perf_counter()
(x_min, y_min, x_max, y_max) = bounding_box(points)
end = time.perf_counter()
print('elapsed time = {0:10.6f} seconds'.format(end - start))
if do_hull:
print('convex hull...')
start = time.perf_counter()
hull = convex_hull(points)
end = time.perf_counter()
print('elapsed time = {0:10.6f} seconds'.format(end - start))
w = tkinter.Canvas(tkinter.Tk(),
width=CANVAS_WIDTH,
height=CANVAS_HEIGHT)
w.pack()
if do_box:
w.create_polygon([canvas_x(x_min), canvas_y(y_min),
canvas_x(x_min), canvas_y(y_max),
canvas_x(x_max), canvas_y(y_max),
canvas_x(x_max), canvas_y(y_min)],
outline=BOX_OUTLINE_COLOR,
fill=BOX_FILL_COLOR,
width=OUTLINE_WIDTH)
if do_hull:
vertices = []
for p in clockwise(hull):
vertices.append(canvas_x(p.x))
vertices.append(canvas_y(p.y))
w.create_polygon(vertices,
outline=HULL_OUTLINE_COLOR,
fill=HULL_FILL_COLOR,
width=OUTLINE_WIDTH)
#to aid in debug...
for p in hull:
w.create_oval(canvas_x(p.x) - POINT_RADIUS,
canvas_y(p.y) - POINT_RADIUS,
canvas_x(p.x) + POINT_RADIUS,
canvas_y(p.y) + POINT_RADIUS,
fill='magenta')
for p in points:
if p not in hull:
w.create_oval(canvas_x(p.x) - POINT_RADIUS,
canvas_y(p.y) - POINT_RADIUS,
canvas_x(p.x) + POINT_RADIUS,
canvas_y(p.y) + POINT_RADIUS,
fill=INTERIOR_POINT_COLOR)
tkinter.mainloop()
示例8: __init__
def __init__(self):
def run_payroll_button():
self.main_window.destroy()
src.accounting.run_payroll.RunPayroll()
src.views.payroll_complete_gui.RunPayrollGUI()
def cancel_payroll_button():
self.main_window.destroy()
src.views.main_gui.MainGUI()
self.main_window = tkinter.Tk()
self.bottom_frame = tkinter.Frame(self.main_window)
canvas = Canvas(width=1250, height=720, bg='black')
canvas.pack(expand=YES, fill=BOTH)
gif2 = PhotoImage(file='../src/images/wallpaper.gif')
canvas.create_image(0, 0, image=gif2, anchor=NW)
start_button = Button(canvas, text="Start Daily Payroll", command=run_payroll_button, anchor=W)
start_button.configure(width=15, activebackground="#33B5E5", relief=FLAT)
start_button_window = canvas.create_window(450, 375, anchor=NW, window=start_button)
cancel_button = Button(canvas, text="Cancel", command=cancel_payroll_button, anchor=W)
cancel_button.configure(width=15, activebackground="#33B5E5", relief=FLAT)
cancel_button_window = canvas.create_window(650, 375, anchor=NW, window=cancel_button)
tkinter.mainloop()
示例9: after_install_gui
def after_install_gui(self):
top = tkinter.Tk()
top.geometry('300x150')
top.title("AutoTrace")
label = tkinter.Label(top, text = "Welcome to Autotrace!",
font = 'Helvetica -18 bold')
label.pack(fill=tkinter.Y, expand=1)
folder = tkinter.Button(top, text='Click here to view Autotrace files',
command = lambda: (os.system("open "+self.github_path)))
folder.pack()
readme = tkinter.Button(top, text='ReadMe',
command = lambda: (os.system("open "+os.path.join(self.github_path, "README.md"))), activeforeground ='blue',
activebackground = 'green')
readme.pack()
apilsite = tkinter.Button(top, text='Look here for more info on the project',
command = lambda: (webbrowser.open("http://apil.arizona.edu")), activeforeground = 'purple',
activebackground = 'orange')
apilsite.pack()
quit = tkinter.Button(top, text='Quit',
command=top.quit, activeforeground='red',
activebackground='black')
quit.pack()
tkinter.mainloop()
示例10: _selftest
def _selftest():
class content:
def __init__(self):
Button(self, text='Larch', command=self.quit).pack()
Button(self, text='Sing', command=self.destroy).pack()
class contentmix(MainWindow, content):
def __init__(self):
MainWindow.__init__(self, 'mixin', 'Main')
content.__init__(self)
contentmix()
class contentmix(PopupWindow, content):
def __init__(self):
PopupWindow.__init__(self, 'mixin', 'Popup')
content.__init__(self)
prev = contentmix()
class contentmix(ComponentWindow, content):
def __init__(self):
ComponentWindow.__init__(self, prev)
content.__init__(self)
contentmix()
class contentsub(PopupWindow):
def __init__(self):
PopupWindow.__init__(self, 'popup', 'subclass')
Button(self, text='Pine', command=self.quit).pack()
Button(self, text='Sing', command=self.destroy).pack()
contentsub()
win = PopupWindow('popup', 'attachment')
Button(win, text='Redwood', command=win.quit).pack()
Button(win, text='Sing', command=win.destroy).pack()
mainloop()
示例11: game_play
def game_play():
s= input("Resume (y/n)?")
if s=="y":
file = open("Nathansettings",'rb')
x = pickle.load(file)
y = pickle.load(file)
file.close()
else: x=y=100
game_map = Map()
game_map.x = x
game_map.y = y
game_map.make_arc()
game_map.draw()
# this tells the graphics system to go into an infinite loop and just follow whatever events come along.
tkinter.mainloop()
s= tkinter.messagebox.askyesno("Save state","Save?")
if s:
file = open("Nathansettings",'wb')
pickle.dump(game_map.x,file)
pickle.dump(game_map.y,file)
file.close()
print("Thanks for playing")
game_map.root.destroy()
示例12: PropExchange3
def PropExchange3(self):
# Get the user input fron the previous gui
giveProp= self.propEntry.get()
# Destroy previous Gui
self.PropExchangeGUI2.destroy()
# Validate player input
if giveProp in self.__Player.get_PropertyDict() or giveProp == 'None':
self.__TradeList.append(giveProp)
# Create new GUI to get how much cash the player wants to give up or get
self.PropExchangeGUI3= tkinter.Tk(className=' Trading Property')
# Display message to player
self.cashLabel= tkinter.Label(self.PropExchangeGUI3, text='How much cash do you want to give?')
# Get player to enter number
self.cashEntry= tkinter.Entry(self.PropExchangeGUI3, width=20)
# Create 'Confirm' button
self.confirmButton= tkinter.Button(self.PropExchangeGUI3, text='Confirm', command=self.PropExchangeAction)
# Pack Label, Entry and Button
self.cashLabel.pack()
self.cashEntry.pack()
self.confirmButton.pack()
tkinter.messagebox.showinfo('Information', "Enter a negative to GET cash from computer.\nEg. -240.90")
tkinter.mainloop()
else:
tkinter.messagebox.showinfo('Warning', giveProp + " is not owned by you, squatter.\nEnter a property you LEGALLY own.")
# Call the previous gui again to allow the player to reenter name
self.PropExchange2()
示例13: PropExchange2
def PropExchange2(self):
# Get user input from previous gui
wantProp= self.propEntry.get()
# Destroy previous Gui
self.PropExchangeGUI1.destroy()
# Validate player input
if wantProp in self.__Danny.get_PropertyDict() or wantProp == 'None':
self.__TradeList.append(wantProp)
# Create new GUI to get name of properties the player wants to give up
self.PropExchangeGUI2= tkinter.Tk(className=' Trading Property')
# Display message to player
self.propLabel= tkinter.Label(self.PropExchangeGUI2, text='Enter the name of the property you want to give up:')
# Get player to enter name
self.propEntry= tkinter.Entry(self.PropExchangeGUI2, width=20)
# Create 'Confirm' button
self.confirmButton= tkinter.Button(self.PropExchangeGUI2, text='Confirm', command=self.PropExchange3)
# Pack Label, Entry and Button
self.propLabel.pack()
self.propEntry.pack()
self.confirmButton.pack()
tkinter.messagebox.showinfo(self.__Player.get_name() + "'s Property List", self.__Player.get_name() + 's Property List:\n' + self.__Player.getPropListasString())
print("-- ", self.__Player.get_name(), "'s Property --", sep='')
print('\n' + self.__Player.getPropListasString())
tkinter.mainloop()
else:
tkinter.messagebox.showinfo('Warning', wantProp + " is not owned by Danny.\nEnter another property.")
# Call the previous gui again to allow the player to reenter name
self.PropExchange1()
示例14: __init__
def __init__(self):
# Create the main window widget.
self.main_window = tkinter.Tk()
# Create a Button widget. The text 'Click Me!'
# should appear on the face of the Button. The
# do_something method should be executed when
# the user clicks the Button.
self.my_button = tkinter.Button(self.main_window, \
text='Click Me!', \
command=self.do_something)
# Create a Quit button. When this button is clicked
# the root widget's destroy method is called.
# (The main_window variable references the root widget,
# so the callback function is self.main_window.destroy.)
self.quit_button = tkinter.Button(self.main_window, \
text='Quit', \
command=self.main_window.destroy)
# Pack the Buttons.
self.my_button.pack()
self.quit_button.pack()
# Enter the tkinter main loop.
tkinter.mainloop()
示例15: __init__
def __init__(self):
self.main_window = tkinter.Tk() #Create main window
self.main_window.title('Paddocks - T3 G3')
main_frame = self.create_frame() #Creates the main frame
menu_frame = self.create_menu() #Create a menu to save, load, and quit
title = tkinter.Label(self.main_window, \
text = 'PADDOCKS', \
font = ('Comic Sans MS',16)) # this is a lemonade stand right?
file_instruct = tkinter.Label(self.main_window, \
text = 'File to load / Save as :', \
font = ('Comic Sans MS',10)) # this is a lemonade stand right?
self.file_entry = tkinter.Entry(self.main_window, \
width = 24) # lets user specify the file name to load/save
instruct = tkinter.Label(self.main_window, \
text = "HOW TO PLAY:\n- First person to finish 5 boxes wins!\n- Your boxes are marked with (H) and the computers are marked with (C).\n- To save or load a game, type in the name of the file you want to save as, or load.", \
wraplength = 200)
# specifies how the widgets above are placed in the window.
title.grid(row = 0, column = 0)
file_instruct.grid(row = 1, column = 0)
main_frame.grid(row = 2, column = 0)
self.file_entry.grid(row = 1, column = 1)
instruct.grid(row = 2, column = 1)
menu_frame.grid(row = 0, column = 1)
tkinter.mainloop()