本文整理汇总了Python中PIL.ImageTk.PhotoImage方法的典型用法代码示例。如果您正苦于以下问题:Python ImageTk.PhotoImage方法的具体用法?Python ImageTk.PhotoImage怎么用?Python ImageTk.PhotoImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIL.ImageTk
的用法示例。
在下文中一共展示了ImageTk.PhotoImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_image_scaled
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def get_image_scaled(image):
# Calculate the aspect ratio of the image
image_aspect = float(image.size[1]) / float(image.size[0])
# Scale the image
image_scaled = (s.WINDOW_WIDTH, int(s.WINDOW_WIDTH * image_aspect))
if image_aspect > 1:
image_scaled = (int(s.WINDOW_HEIGHT / image_aspect), s.WINDOW_HEIGHT)
coords = ((s.WINDOW_WIDTH - image_scaled[0])/2,
(s.WINDOW_HEIGHT - image_scaled[1])/2,
image_scaled[0], image_scaled[1])
# Creat the resized image and return it and the co-ordinates.
return ImageTk.PhotoImage(
image.resize(image_scaled, Image.ANTIALIAS)), coords
# -----------------------------------------------------------------------------
# Function to output the co-ordinates of the boxes
# -----------------------------------------------------------------------------
示例2: __init__
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk 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
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk 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
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk 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: update_preview
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def update_preview(self, psize):
# Safety check: Ignore calls during construction/destruction.
if not self.init_done: return
# Copy latest user settings to the lens object.
self.lens.fov_deg = self.f.get()
self.lens.radius_px = self.r.get()
self.lens.center_px[0] = self.x.get()
self.lens.center_px[1] = self.y.get()
# Re-scale the image to match the canvas size.
# Note: Make a copy first, because thumbnail() operates in-place.
self.img_sc = self.img.copy()
self.img_sc.thumbnail(psize, Image.NEAREST)
self.img_tk = ImageTk.PhotoImage(self.img_sc)
# Re-scale the x/y/r parameters to match the preview scale.
pre_scale = float(psize[0]) / float(self.img.size[0])
x = self.x.get() * pre_scale
y = self.y.get() * pre_scale
r = self.r.get() * pre_scale
# Clear and redraw the canvas.
self.preview.delete('all')
self.preview.create_image(0, 0, anchor=tk.NW, image=self.img_tk)
self.preview.create_oval(x-r, y-r, x+r, y+r,
outline='#C00000', width=3)
# Make a combined label/textbox/slider for a given variable:
示例6: ShowMol
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def ShowMol(mol, size=(300, 300), kekulize=True, wedgeBonds=True, title='RDKit Molecule', **kwargs):
""" Generates a picture of a molecule and displays it in a Tkinter window
"""
global tkRoot, tkLabel, tkPI
try:
import Tkinter
except ImportError:
import tkinter as Tkinter
try:
import ImageTk
except ImportError:
from PIL import ImageTk
img = MolToImage(mol, size, kekulize, wedgeBonds, **kwargs)
if not tkRoot:
tkRoot = Tkinter.Tk()
tkRoot.title(title)
tkPI = ImageTk.PhotoImage(img)
tkLabel = Tkinter.Label(tkRoot, image=tkPI)
tkLabel.place(x=0, y=0, width=img.size[0], height=img.size[1])
else:
tkPI.paste(img)
tkRoot.geometry('%dx%d' % (img.size))
示例7: get_imgtk
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def get_imgtk(self, img_bgr):
img = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
im = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=im)
wide = imgtk.width()
high = imgtk.height()
if wide > self.viewwide or high > self.viewhigh:
wide_factor = self.viewwide / wide
high_factor = self.viewhigh / high
factor = min(wide_factor, high_factor)
wide = int(wide * factor)
if wide <= 0 : wide = 1
high = int(high * factor)
if high <= 0 : high = 1
im=im.resize((wide, high), Image.ANTIALIAS)
imgtk = ImageTk.PhotoImage(image=im)
return imgtk
示例8: show_roi
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def show_roi(self, r, roi, color):
if r :
roi = cv2.cvtColor(roi, cv2.COLOR_BGR2RGB)
roi = Image.fromarray(roi)
self.imgtk_roi = ImageTk.PhotoImage(image=roi)
self.roi_ctl.configure(image=self.imgtk_roi, state='enable')
self.r_ctl.configure(text=str(r))
self.update_time = time.time()
try:
c = self.color_transform[color]
self.color_ctl.configure(text=c[0], background=c[1], state='enable')
except:
self.color_ctl.configure(state='disabled')
elif self.update_time + 8 < time.time():
self.roi_ctl.configure(state='disabled')
self.r_ctl.configure(text="")
self.color_ctl.configure(state='disabled')
示例9: resize_img
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def resize_img(self,sl):
rimg = cv2.resize(self.img8[sl[1],sl[0]],tuple(reversed(self.img_shape)),
interpolation=0)
if self.select_box[0] > 0:
lbox = [0]*4
for i in range(4):
n = self.select_box[i]-self.zoom_window[i%2]*self.img.shape[i%2]
n /= (self.zoom_window[2+i%2]-self.zoom_window[i%2])
lbox[i] = int(n/self.img.shape[i%2]*
self.img_shape[i%2])
self.draw_box(lbox,rimg)
if self.boxes:
for b in self.boxes:
lbox = [0]*4
for i in range(4):
n = b[i]-self.zoom_window[i%2]*self.img.shape[i%2]
n /= (self.zoom_window[2+i%2]-self.zoom_window[i%2])
lbox[i] = int(n/self.img.shape[i%2]*
self.img_shape[i%2])
self.draw_box(lbox,rimg)
self.c_img = ImageTk.PhotoImage(Image.fromarray(rimg))
示例10: previewbarcode
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def previewbarcode(self, bcodevalue):
tmpbarcode = self.generatebarcode(bcodevalue)
validbc = tmpbarcode.validate_draw_barcode()
if(validbc):
image1 = ImageTk.PhotoImage(validbc)
self.imagepanel.create_image(
validbc.size[0] / 2, validbc.size[1] / 2, image=image1)
self.imagepanel.config(
scrollregion=(
0,
0,
validbc.size[0],
validbc.size[1]))
self.imagepanel.image = image1
self.already_exist(False, bcodevalue)
else:
mbox.showerror("Error", "Barcode couldn't be generated!")
示例11: popup_choice
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def popup_choice(self, window, title, image, text, choices):
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(func):
popup.destroy()
if func != None:
func()
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, columnspan=len(choices), padx=10, pady=10)
for idx, choice in enumerate(choices):
run_end_func = partial(run_end, choice[1])
tk.Button(popup, text=choice[0], command=run_end_func).grid(column=1 + idx, row=1, padx=10, pady=10)
popup.wait_visibility()
popup.grab_set()
popup.wait_window()
示例12: simple_window
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def simple_window():
root = tk.Tk()
image = np.zeros((128, 128, 3), dtype=np.uint8)
image[32:96, 32:96, 0] = 255
im = Image.fromarray(image)
im = ImageTk.PhotoImage(im)
image = np.zeros((128, 128, 3), dtype=np.uint8)
image[32:96, 32:96, 1] = 255
im2 = Image.fromarray(image)
im2 = ImageTk.PhotoImage(im2)
panel = tk.Label(root, image=im)
def left_key(event):
panel.configure(image=im2)
panel.image = im2
def quit(event):
sys.exit()
panel.bind('<Left>', left_key)
panel.bind('<Up>', left_key)
panel.bind('<Down>', left_key)
panel.bind('q', quit)
panel.focus_set()
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()
示例13: __init__
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def __init__(self, img):
parent = Tk()
Frame.__init__(self, parent)
self.pack(fill=BOTH, expand=1)
label1 = Label(self)
label1.photo = ImageTk.PhotoImage(img)
label1.config(image=label1.photo)
label1.pack(fill=BOTH, expand=1)
parent.mainloop()
示例14: drawPlaceholder
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def drawPlaceholder():
global root
global canvas
global canvas_image
default_im = ImageTk.PhotoImage(image=iim)
canvas.itemconfig(canvas_image, image = default_im)
root.update()
示例15: drawCourse
# 需要导入模块: from PIL import ImageTk [as 别名]
# 或者: from PIL.ImageTk import PhotoImage [as 别名]
def drawCourse(cjson):
global root
global canvas
global canvas_image
data = drawCourseAsImage(cjson)
im = Image.fromarray((255.0*data).astype(np.uint8), 'RGB').resize((image_width, image_height), Image.NEAREST)
im = im.transpose(Image.FLIP_TOP_BOTTOM)
cim = ImageTk.PhotoImage(image=im)
canvas.img = cim # Need to save reference to ImageTK
canvas.itemconfig(canvas_image, image = cim)
drawScorecard(cjson)
root.update()