本文整理汇总了Python中tkinter.PhotoImage方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.PhotoImage方法的具体用法?Python tkinter.PhotoImage怎么用?Python tkinter.PhotoImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter.PhotoImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ui
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def ui():
root = tkinter.Tk()
root.title('PDF和照片互转器') # 标题
root.resizable(width=False, height=False) # 防止大小调整
canvas = tkinter.Canvas(root, width=450, height=320, highlightthickness=0) # 创建画布
photo = tkinter.PhotoImage(file=file_zip_path + os.sep + 'pdf.png') # 获取背景图片的网络连接
canvas.create_image(225, 160, image=photo)
select_dir_button = tkinter.Button(root, text="选择照片文件夹", command=select_dir, bg='yellow') # 创建按钮
select_pdf_button = tkinter.Button(root, text="选择PDF文件", command=select_pdf, bg='green')
click_button = tkinter.Button(root, text="点击执行", command=start, bg='blue')
select_dir_button.pack() # 启动按钮
select_pdf_button.pack()
click_button.pack()
canvas.create_window(240, 120, width=100, height=30, window=select_dir_button) # 将按钮创建到画布
canvas.create_window(240, 190, width=100, height=30, window=select_pdf_button)
canvas.create_window(240, 260, width=100, height=30, window=click_button)
canvas.pack() # 启动画布
root.mainloop() # 主程序循环
示例2: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.master = master
self.init_window()
self.about_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/LPHK-banner.png"))
self.info_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/info.png"))
self.warning_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/warning.png"))
self.error_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/error.png"))
self.alert_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/alert.png"))
self.scare_image = ImageTk.PhotoImage(Image.open(PATH + "/resources/scare.png"))
self.grid_drawn = False
self.grid_rects = [[None for y in range(9)] for x in range(9)]
self.button_mode = "edit"
self.last_clicked = None
self.outline_box = None
示例3: popup
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def popup(self, window, title, image, text, button_text, end_command=None):
popup = tk.Toplevel(window)
popup.resizable(False, False)
if MAIN_ICON != None:
if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
dummy = None
#popup.call('wm', 'iconphoto', popup._w, tk.PhotoImage(file=MAIN_ICON))
else:
popup.iconbitmap(MAIN_ICON)
popup.wm_title(title)
popup.tkraise(window)
def run_end():
popup.destroy()
if end_command != None:
end_command()
picture_label = tk.Label(popup, image=image)
picture_label.photo = image
picture_label.grid(column=0, row=0, rowspan=2, padx=10, pady=10)
tk.Label(popup, text=text, justify=tk.CENTER).grid(column=1, row=0, padx=10, pady=10)
tk.Button(popup, text=button_text, command=run_end).grid(column=1, row=1, padx=10, pady=10)
popup.wait_visibility()
popup.grab_set()
popup.wait_window()
示例4: make
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def make():
global root
global app
global root_destroyed
global redetect_before_start
root = tk.Tk()
root_destroyed = False
root.protocol("WM_DELETE_WINDOW", close)
root.resizable(False, False)
if MAIN_ICON != None:
if os.path.splitext(MAIN_ICON)[1].lower() == ".gif":
root.call('wm', 'iconphoto', root._w, tk.PhotoImage(file=MAIN_ICON))
else:
root.iconbitmap(MAIN_ICON)
app = Main_Window(root)
app.raise_above_all()
app.after(100, app.connect_lp)
app.mainloop()
示例5: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self):
root = tk.Tk()
# show no frame
root.overrideredirect(True)
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (self.width / 2)
y = (hs / 2) - (self.height / 2)
root.geometry('%dx%d+%d+%d' % (self.width, self.height, x, y))
image = tk.PhotoImage(file=self.image_file)
canvas = tk.Canvas(root, height=self.height, width=self.width, bg="brown")
canvas.create_image(self.width/2, self.height/2, image=image)
canvas.pack()
root.after(2500, root.destroy)
root.mainloop()
示例6: load_friends
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def load_friends(self):
all_users = self.requester.get_all_users()
for user in all_users:
if user['username'] != self.username:
friend_frame = ttk.Frame(self.canvas_frame)
profile_photo = tk.PhotoImage(file="images/avatar.png")
profile_photo_label = ttk.Label(friend_frame, image=profile_photo)
profile_photo_label.image = profile_photo
friend_name = ttk.Label(friend_frame, text=user['real_name'], anchor=tk.W)
message_this_friend = partial(self.open_chat_window, username=user["username"], real_name=user["real_name"])
message_button = ttk.Button(friend_frame, text="Chat", command=message_this_friend)
profile_photo_label.pack(side=tk.LEFT)
friend_name.pack(side=tk.LEFT)
message_button.pack(side=tk.RIGHT)
friend_frame.pack(fill=tk.X, expand=1)
示例7: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self, master, **kwargs):
super().__init__(**kwargs)
self.master = master
self.transient(master)
self.position_window()
smilie_files = [file for file in os.listdir(self.smilies_dir) if file.endswith(".png")]
self.smilie_images = []
for file in smilie_files:
full_path = os.path.join(self.smilies_dir, file)
image = tk.PhotoImage(file=full_path)
self.smilie_images.append(image)
for index, file in enumerate(self.smilie_images):
row, col = divmod(index, 3)
button = ttk.Button(self, image=file, command=lambda s=file: self.insert_smilie(s))
button.grid(row=row, column=col, sticky='nsew')
for i in range(3):
tk.Grid.columnconfigure(self, i, weight=1)
tk.Grid.rowconfigure(self, i, weight=1)
示例8: load_friends
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def load_friends(self):
friend_frame = ttk.Frame(self.canvas_frame)
profile_photo = tk.PhotoImage(file="images/avatar.png")
profile_photo_label = ttk.Label(friend_frame, image=profile_photo)
profile_photo_label.image = profile_photo
friend_name = ttk.Label(friend_frame, text="Jaden Corebyn", anchor=tk.W)
message_button = ttk.Button(friend_frame, text="Chat", command=self.open_chat_window)
profile_photo_label.pack(side=tk.LEFT)
friend_name.pack(side=tk.LEFT)
message_button.pack(side=tk.RIGHT)
friend_frame.pack(fill=tk.X, expand=1)
示例9: receive_message
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def receive_message(self, message, smilies):
"""
Writes message into messages_area
:param message: message text
:param smilies: list of tuples of (char_index, smilie_file), where char_index is the x index of the smilie's location
and smilie_file is the file name only (no path)
:return: None
"""
self.messages_area.configure(state='normal')
self.messages_area.insert(tk.END, message)
if len(smilies):
last_line_no = self.messages_area.index(tk.END)
last_line_no = str(last_line_no).split('.')[0]
last_line_no = str(int(last_line_no) - 2)
for index, file in smilies:
smilie_path = os.path.join(SmilieSelect.smilies_dir, file)
image = tk.PhotoImage(file=smilie_path)
smilie_index = last_line_no + '.' + index
self.messages_area.image_create(smilie_index, image=image)
self.messages_area.configure(state='disabled')
示例10: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self, master):
super().__init__()
self.master = master
self.transient(master)
self.title("Change Avatar")
self.geometry("350x200")
self.image_file_types = [
("Png Images", ("*.png", "*.PNG")),
]
self.current_avatar_image = tk.PhotoImage(file=avatar_file_path)
self.current_avatar = ttk.Label(self, image=self.current_avatar_image)
choose_file_button = ttk.Button(self, text="Choose File", command=self.choose_image)
self.current_avatar.pack()
choose_file_button.pack()
示例11: choose_image
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def choose_image(self):
image_file = filedialog.askopenfilename(filetypes=self.image_file_types)
if image_file:
avatar = Image.open(image_file)
avatar.thumbnail((128, 128))
avatar.save(avatar_file_path, "PNG")
img_contents = ""
img_b64 = ""
with open(avatar_file_path, "rb") as img:
img_contents = img.read()
img_b64 = base64.urlsafe_b64encode(img_contents)
self.master.requester.update_avatar(self.master.username, img_b64)
self.current_avatar_image = tk.PhotoImage(file=avatar_file_path)
self.current_avatar.configure(image=self.current_avatar_image)
示例12: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self, master):
self.button = ttk.Button(master, text = 'Click me')
self.button.pack()
self.button.config(command = self.buttonfunc) # configure a command for button click
self.btn1 = ttk.Button(master, text = 'Click on \'Click me\'', command = self.invokebutton)
self.btn1.pack()
self.btn2 = ttk.Button(master, text = 'Disable \'Click me\'', command = self.disableButton)
self.btn2.pack()
self.btn3 = ttk.Button(master, text = 'Enable \'Click me\'', command = self.enableButton)
self.btn3.pack()
self.btn4 = ttk.Button(master, text = 'Query state of \'Click me\'', command = self.queryButtonState)
self.btn4.pack()
self.button.img = tk.PhotoImage(file = 'simple_gif.gif')
self.button.img = self.button.img.subsample(10, 10) # take every 5th pixel in x and y direction of image
self.btn5 = ttk.Button(master, text = 'Add image to \'Click me\'', command = self.addImage)
self.btn5.pack()
self.label = ttk.Label(master, text = 'No button pressed yet.')
self.label.pack()
示例13: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self, master): # constructor method
# define list of label texts
self.greet_list = ('Hello, World! This is python GUI.', \
'Hello, This is Python GUI. Sadly, I was made to say Hello only. I will love to say so much more.')
# creat label as a child of root window with some text.
self.label = ttk.Label(master, text = self.greet_list[0])
self.btn = ttk.Button(master, text = 'Greet Again', command = self.handle_text) # create a button
# store image in the label obj to keep it in the scope as
# long as label is displayed and to avoid getting the image getting garbage collected
imgpath = 'simple_gif.gif' # path of the image
self.label.img = tk.PhotoImage(file = imgpath) # read_image :: saving image within label_object to prevent its garbage collection
self.label.config(image = self.label.img) # display image in label widget
self.label.config(compound = 'left') # to display image in left of text
self.label.pack() # pack label to the window with pack() geometry method of Label
self.btn.pack()
self.label.config(wraplength = 200) # specify wraplength of text in label
self.label.config(justify = tk.CENTER) # justify text in label to (CENTER, RIGHT or LEFT)
self.label.config(foreground = 'blue', background = 'yellow') # insert font color (foreground) and background color
self.label.config(font = ('Times', 10, 'bold')) # font = (font_name, font_size, font_type)
示例14: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self, image, initialField, initialText):
frm = tk.Frame(root)
frm.config(background="white")
self.image = tk.PhotoImage(format='gif',data=images[image.upper()])
self.imageDimmed = tk.PhotoImage(format='gif',data=images[image])
self.img = tk.Label(frm)
self.img.config(borderwidth=0)
self.img.pack(side = "left")
self.fld = tk.Text(frm, **fieldParams)
self.initScrollText(frm,self.fld,initialField)
frm = tk.Frame(root)
self.txt = tk.Text(frm, **textParams)
self.initScrollText(frm,self.txt,initialText)
for i in range(2):
self.txt.tag_config(colors[i], background = colors[i])
self.txt.tag_config("emph"+colors[i], foreground = emphColors[i])
示例15: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import PhotoImage [as 别名]
def __init__(self):
self.root = tkinter.Tk()
self.root.title("Mandelbrot (Pyro multi CPU core version)")
canvas = tkinter.Canvas(self.root, width=res_x, height=res_y, bg="#000000")
canvas.pack()
self.img = tkinter.PhotoImage(width=res_x, height=res_y)
canvas.create_image((res_x/2, res_y/2), image=self.img, state="normal")
with locate_ns() as ns:
mandels = ns.yplookup(meta_any={"class:mandelbrot_calc_color"})
mandels = list(mandels.items())
print("{0} mandelbrot calculation servers found.".format(len(mandels)))
if not mandels:
raise ValueError("launch at least one mandelbrot calculation server before starting this")
self.mandels = [uri for _, (uri, meta) in mandels]
self.pool = futures.ThreadPoolExecutor(max_workers=len(self.mandels))
self.tasks = []
self.start_time = time.time()
for line in range(res_y):
self.tasks.append(self.calc_new_line(line))
self.root.after(100, self.draw_results)
tkinter.mainloop()