本文整理汇总了Python中tkinter.Label.image方法的典型用法代码示例。如果您正苦于以下问题:Python Label.image方法的具体用法?Python Label.image怎么用?Python Label.image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Label
的用法示例。
在下文中一共展示了Label.image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_button_click
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def handle_button_click(self, event):
val = self.button_selected.get() - 1
val = self.radio_buttons.index(event.widget)
if event.state & 0x001: # Shift key down
self.x_flipped[val] = not self.x_flipped[val]
try:
raise IOError
image_file = imget(self.img_lists[val][self.images_selected[val]])
import_image = Image.open(image_file)
except IOError:
image_file = imget_bdgp(self.img_lists[val][self.images_selected[val]])
import_image = Image.open(image_file)
import_image = import_image.resize((180,80), Image.ANTIALIAS)
import_image = import_image.rotate(180*self.x_flipped[val])
embryo_image = ImageTk.PhotoImage(import_image)
label = Label(image=embryo_image)
label.image = embryo_image
self.radio_buttons[val].configure(
#text=image_file,
image=label.image,
)
elif event.state & 0x004: # Control key down
popup = Menu(root, tearoff=0)
popup.add_command(label=self.radio_buttons[val].cget('text'))
popup.add_separator()
popup.add_command(label="Invert X")
popup.add_command(label="Invert Y")
try:
popup.tk_popup(event.x_root, event.y_root, 0)
finally:
# make sure to release the grab (Tk 8.0a1 only)
popup.grab_release()
elif val >= 0:
self.images_selected[val] = ((self.images_selected[val] + 2*event.num
- 3) %
len(self.img_lists[val]))
self.x_flipped[val] = False
if self.images_selected[val] == 0:
stdout.write('\a')
stdout.flush()
try:
raise IOError
image_file = imget(self.img_lists[val][self.images_selected[val]])
import_image = Image.open(image_file)
except IOError:
image_file = imget_bdgp(self.img_lists[val][self.images_selected[val]])
import_image = Image.open(image_file)
import_image = import_image.resize((180,80), Image.ANTIALIAS)
embryo_image = ImageTk.PhotoImage(import_image)
label = Label(image=embryo_image)
label.image = embryo_image
self.radio_buttons[val].configure(
#text=image_file,
image=label.image,
)
self.image_files[val] = image_file
self.button_selected.set(-1)
示例2: display_image
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def display_image(title,image):
win = Toplevel(root)
photo = ImageTk.PhotoImage(image)
win.title(title)
label = Label(win,image=photo)
label.image = photo #Kludge: keep a reference to avoid garbage collection!
label.pack()
示例3: home_page
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def home_page(self, master):
frame = Frame(master)
frame.grid(row=0, column=0)
image = PhotoImage(file="img/guido.gif")
bg = Label(frame, image=image)
bg.image = image
bg.grid(row=0, column=0, rowspan=4, columnspan=2)
index = 0
while index < 3:
frame.grid_columnconfigure(index, minsize=200)
frame.grid_rowconfigure(index, minsize=80)
index += 1
summary_button = HomeButton(frame, self.to_summary, 'img/summary.png')
summary_button.grid(row=0, column=0, sticky='w')
edit_button = HomeButton(frame, self.to_edit, 'img/edit.png')
edit_button.grid(row=0, column=1, sticky='e')
momentary_button = HomeButton(frame, self.to_momentary, 'img/momentary.png')
momentary_button.grid(row=1, column=0, sticky='w')
preferences_button = HomeButton(frame, self.to_pref, 'img/preferences.png')
preferences_button.grid(row=1, column=1, sticky='e')
music = HomeButton(frame, self.to_summary, 'img/music.png')
music.grid(row=2, column=0, sticky='w')
info = HomeButton(frame, self.to_summary, 'img/info.png')
info.grid(row=2, column=1, sticky='e')
return frame
示例4: make_widgets
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def make_widgets(self):
self.lines = ['Red Line', 'Blue Line', 'Brown Line', 'Purple Line',
'Orange Line', 'Green Line', 'Pink Line', 'Yellow Line']
headimg = PhotoImage(file='header.gif')
header = Label(self, image=headimg)
header.image = headimg
header.grid(row=0, columnspan=2)
r = 1
c = 0
for b in self.lines:
rel = 'ridge'
cmd = lambda x=b: self.click(x)
splt = b.split()
if splt[0] not in 'OrangeGreenPinkYellow':
Button(self,text=b, width = 19, height=2, relief=rel,
bg = splt[0], fg = "#FFF", font = ("Helvetica", 16),
command=cmd).grid(row=r,column=c)
else:
Button(self,text=b, width = 19, relief=rel,
bg = splt[0], fg = "#000", height=2, font = ("Helvetica", 16),
command=cmd).grid(row=r,column=c)
c += 1
if c > 1:
c = 0
r += 1
示例5: _load_pictures
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def _load_pictures(self, master, path, pictures):
out_pictures = []
for picture in pictures:
img = PhotoImage(file=path + picture)
lbl = Label(master, image=img)
lbl.image = img
out_pictures.append(lbl)
return out_pictures
示例6: create_images
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def create_images(master, path):
fps = extract_file_paths(path)
images = []
for i in fps:
img = PhotoImage(file=i)
lbl = Label(master, image=img)
lbl.image = img
images.append(lbl)
return images
示例7: initUI
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def initUI(self):
self.parent.title("Absolute positioning")
self.pack(fill=BOTH, expand=1)
bard = Image.open("linux_256.jpg")
bardejov = ImageTk.PhotoImage(bard)
label1 = Label(self, image=bardejov)
label1.image = bardejov
label1.place(x=20, y=20)
示例8: _create_label_images
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def _create_label_images(self, master, path):
labels = []
for i in range(4):
img = PhotoImage(file=path + "a" + str(i+1) + ".png")
lbl = Label(master, image=img)
lbl.image = img
labels.append(lbl)
return labels
示例9: create_thumbnail
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def create_thumbnail(image, thumbnail_size):
(width, height) = image.size
print(width, height)
resize_ratio = (min(thumbnail_size/width, thumbnail_size/height))
image.thumbnail((width*resize_ratio, height*resize_ratio), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(image)
photo_label = Label(image=photo)
photo_label.image = photo
return photo
示例10: initUI
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def initUI(self):
self.parent.title("Label")
self.img = Image.open("/home/george/Pictures/shakespeare.jpg")
tatras = ImageTk.PhotoImage(self.img)
label = Label(self, image=tatras)
# reference must be stored
label.image = tatras
label.pack()
self.pack()
示例11: create_widgets
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def create_widgets(self):
logo_image = ImageTk.PhotoImage(Image.open("NeuroVision1024.png").resize((341, 256), Image.ANTIALIAS))
logo_label = Label(self, image=logo_image)
logo_label.image = logo_image
logo_label.pack(side="top", fill="x", pady=10)
correlation_button = tk.Button(self, text="Find Correlation between story and fMRI data",
command=lambda: self.controller.show_frame("CorrelationTaskView"), borderwidth=0)
classification = tk.Button(self, text="Predict emotional response using Classification",
command=lambda: self.controller.show_frame("ClassificationTaskView"), borderwidth=0)
regression_button = tk.Button(self, text="Predict emotional response using Regression",
command=lambda: self.controller.show_frame("RegressionTaskView"), borderwidth=0)
about_button = tk.Button(self, text="About",
command=lambda: self.controller.show_frame("AboutPage"), borderwidth=0)
correlation_button.pack(padx=5, pady=5)
classification.pack(padx=5, pady=5)
regression_button.pack(padx=5, pady=5)
about_button.pack(side="right", padx=5, pady=5)
示例12: draw_changing_grid
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def draw_changing_grid(self):
'''draws the grid that is made at the start of each round'''
softblock = PhotoImage(file='gifs/softblock.gif')
label = Label(image=softblock)
label.image = softblock #keeping a reference
self.rocks = {}
for col in range(self.cols):
for row in range(self.rows):
left = col * self.size
right = left + self.size+.5*self.size
top = row * self.size
bot = top + self.size+.5*self.size
left += .5*self.size
top += .5*self.size
if (row==1 or row==2) and (col==1 or col==2) or \
(row==self.rows-2 or row==self.rows-3) and (col==self.cols-2 or col==self.cols-3) or \
row%2==0 and col%2==0 or \
row==0 or col==0 or row==self.rows-1 or col==self.cols-1:
pass
elif randint(0,100) < 50: #soft block density
self.rocks[(col-1,row-1)] = self.canvas.create_image(
(left+right)/2,(top+bot)/2,image=softblock)
示例13: draw_static_grid
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def draw_static_grid(self):
'''draws the grid that is made at the start of the game'''
hardblock = PhotoImage(file='gifs/hardblock.gif')
label = Label(image=hardblock)
label.image = hardblock #keeping a reference
self.regular = {}
self.absolute = {}
for col in range(self.cols):
for row in range(self.rows):
left = col * self.size
right = left + self.size+.5*self.size
top = row * self.size
bot = top + self.size+.5*self.size
left += .5*self.size
top += .5*self.size
if row%2==0 and col%2==0 or \
row==0 or col==0 or \
row==self.rows-1 or col==self.cols-1: #hardblock
self.absolute[(col-1,row-1)] = self.canvas.create_image(
(left+right)/2,(top+bot)/2,image=hardblock)
else: #walkable
self.regular[(col-1,row-1)] = self.canvas.create_rectangle(
left,top,right,bot,fill='#307100',width=0)
示例14: make_widgets
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def make_widgets(self):
stops = self.stored.keys()
sortedstops = []
for stop in stops:
sortedstops.append(stop)
sortedstops.sort()
stopimg = PhotoImage(file='stop.gif')
pickstop = Label(self, image=stopimg)
pickstop.image = stopimg
pickstop.grid(row=0, columnspan=4)
r = 1
c = 0
for stop in sortedstops:
rel = 'ridge'
cmd = lambda x=stop: self.click(x)
if self.line[0] not in 'OrangeGreenPinkYellow':
Button(self,text=stop, width = 19, relief=rel, fg = "#FFF",
bg = self.line[0], font = ("Helvetica", 8),
command=cmd).grid(row=r,column=c)
else:
Button(self,text=stop, width = 19, relief=rel, fg = "#000",
bg = self.line[0], font = ("Helvetica", 8),
command=cmd).grid(row=r,column=c)
c += 1
if c > 3:
c = 0
r += 1
Button(self, text="< Back", width = 5, relief='ridge',
bg = "#000", fg = "#FFF", font = "Helvetica",
command=self.destroy).grid(row=r+1,columnspan=4)
示例15: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import image [as 别名]
def __init__(self, master, cluster_fname=None, fig_cols = 4, fig_rows = None):
if not cluster_fname:
cluster_fname = tkinter.filedialog.askopenfilename(parent=master,
title="List of genes",
initialdir=path.abspath('./'))
print(cluster_fname)
master.wm_title(cluster_fname)
self.all_in_cluster = [line.strip() for line in open(cluster_fname)]
print("No images", [item for item in self.all_in_cluster
if item not in has_img])
self.imgs_in_cluster = [item for item in self.all_in_cluster
if item in has_img]
print(self.imgs_in_cluster)
print(len(self.imgs_in_cluster), len(self.all_in_cluster), end=' ')
print(len(self.imgs_in_cluster) / float(len(self.all_in_cluster)))
self.img_lists = [[x for x in
st_5_with_lat[(st_5_with_lat['Name2'] == gene)
+(st_5_with_lat['FBgn'] == gene)]['imgfile']]
for gene in self.imgs_in_cluster]
num_genes = len(self.imgs_in_cluster)
self.fig_rows, self.fig_cols = adjust_rows_cols(num_genes,
fig_rows or 0, fig_cols or 0)
self.outfn = path.basename(cluster_fname)[:-4]+'.png'
buttons = Frame(master)
buttons.grid(row=1, column=1)
savebutton = Button(buttons, text="Save", command=self.save)
savebutton.grid(row=2, column = 2)
Button(buttons, text="Add Row", command=self.add_row).grid(row=1,column=3)
Button(buttons, text="Add Col", command=self.add_col).grid(row=3,column=3)
Button(buttons, text="Remove Row",
command=self.remove_row).grid(row=1,column=1)
Button(buttons, text="Remove Col",
command=self.remove_col).grid(row=3,column=1)
images = Frame(master)
images.grid(row=2, column=1)
self.button_selected = IntVar(master, -1)
self.images_selected = [0 for list in self.img_lists]
out_name = '{}.png.txt'.format(path.splitext(path.basename(cluster_fname))[0])
print(out_name)
if path.exists(out_name):
for i, line in enumerate(open(out_name)):
self.images_selected[i] = int(line.split()[0].strip())
self.radio_buttons = []
self.image_files = []
self.x_flipped = []
for i, gene in enumerate(self.imgs_in_cluster):
for image_file_name in self.img_lists[i]:
try:
raise IOError
image_file = imget(image_file_name)
import_image = Image.open(image_file)
except (IOError, OSError):
try:
image_file = imget_bdgp(image_file_name)
import_image = Image.open(image_file)
except Exception as exc:
print(exc)
print(image_file_name, gene)
raise exc
import_image = import_image.resize((180,80), Image.ANTIALIAS)
except urllib.error.HTTPError as exc:
print(image_file_name, gene)
raise exc
embryo_image = ImageTk.PhotoImage(import_image)
label = Label(image=embryo_image)
label.image = embryo_image
b = Button(images,
image = label.image,
width = 200,
height= 100,
text=gene,
#text = image_file,
#variable=self.button_selected,
#command=self.handle_button_click,
#value = i+1,
#indicatoron=0,
)
#ToolTip(b, gene)
b.bind("<Button-1>", self.handle_button_click)
b.bind("<Button-2>", self.handle_button_click)
b.grid(row = i // self.fig_cols, column = i % self.fig_cols)
#w = Tix.Balloon(master, message=gene)
#w.bind_widget(b)
self.image_files.append(image_file)
self.radio_buttons.append(b)
self.x_flipped.append(False)