def draw_maze(self): wall_block_image = Image.open("../IMAGE/wall_block.png") wall_block_image = wall_block_image.resize((size_of_block, size_of_block), Image.ANTIALIAS) wall_block_image = ImageTk.PhotoImage(wall_block_image) food_image = Image.open("../IMAGE/food.png") food_image = food_image.resize((size_of_block, size_of_block), Image.ANTIALIAS) food_image = ImageTk.PhotoImage(food_image) ghost_image = Image.open("../IMAGE/ghost.png") ghost_image = ghost_image.resize((size_of_block, size_of_block), Image.ANTIALIAS) ghost_image = ImageTk.PhotoImage(ghost_image) score_image = Image.open("../IMAGE/score.png") score_image = score_image.resize((180, 130), Image.ANTIALIAS) score_image = ImageTk.PhotoImage(score_image) score_image_frame = self.maze_frame.create_image(self.size[1] * size_of_block + 20, (self.size[0] * size_of_block)//2 - 50, anchor='nw', image=score_image) for row in range(self.size[0]): for column in range(self.size[1]): if self.maze[row][column] == 1: self.maze_frame.create_image(column * size_of_block, row * size_of_block, anchor='nw', image=wall_block_image) if self.maze[row][column] == 2: self.food.append([self.maze_frame.create_image(column * size_of_block, row * size_of_block, anchor='nw', image=food_image), (row, column)]) for row in range(self.size[0]): for column in range(self.size[1]): if self.maze[row][column] == 3: self.monster.append([self.maze_frame.create_image(column * size_of_block, row * size_of_block, anchor='nw', image=ghost_image), (row, column)]) self.maze_frame.image = [wall_block_image, food_image, ghost_image, score_image]
def draw_pacman(self): pacman_image = Image.open("../IMAGE/pacman.png") pacman_image = pacman_image.resize((size_of_block, size_of_block), Image.ANTIALIAS) pacman_image = ImageTk.PhotoImage(pacman_image) self.pacman = self.maze_frame.create_image(self.pacman_pos[1] * size_of_block, self.pacman_pos[0] * size_of_block, anchor='nw', image=pacman_image) self.maze_frame.image.append(pacman_image)
def GOBoardElement(self, window): imgWidth = "500" imgHeight = "500" img = Image.open("GO9by9.png") img = img.resize(imgWidth + "x" + imgHeight) img = ImageTk.PhotoImage(img) panel = window.Label(window, image=img) panel.image = img panel.place(relheight=.095, relwidth=0.25, relx=0.7, rely=0.03)
def colorfilter(): global panel x = openfn() u = color123() color_image = Image.open(x) bw = color_image.convert('L') img = bw.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO")
def open_img(): global panel x = openfn() img = Image.open(x) img = img.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img #panel.image = NONE panel.pack(side="top", fill="both", expand="NO")
def gradient(): global panel img = Image.new('RGB', (300, 200), (150, 150, 255)) draw = ImageDraw.Draw(img) draw.rectangle((100, 100, 150, 100), fill=(255, 120, 232)) draw.ellipse((25, 25, 75, 75), fill=(255, 110, 0)) #img.save('test.gif', 'GIF', transparency=0) img = img.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO")
def decrypt(): # load the image and convert it into a numpy array and display on the GUI. load = Image.open("Syngenta.jpg") load.thumbnail(image_display_size, Image.ANTIALIAS) load = np.asarray(load) load = Image.fromarray(np.uint8(load)) render = ImageTk.PhotoImage(load) img = Label(app, image=render) img.image = render img.place(x=100, y=50) # Algorithm to decrypt the data from the image img = cv2.imread("Syngenta.jpg") data = [] stop = False for index_i, i in enumerate(img): i.tolist() for index_j, j in enumerate(i): if ((index_j) % 3 == 2): # first pixel data.append(bin(j[0])[-1]) # second pixel data.append(bin(j[1])[-1]) # third pixel if (bin(j[2])[-1] == '1'): stop = True break else: # first pixel data.append(bin(j[0])[-1]) # second pixel data.append(bin(j[1])[-1]) # third pixel data.append(bin(j[2])[-1]) if (stop): break message = [] # join all the bits to form letters (ASCII Representation) for i in range(int((len(data) + 1) / 8)): message.append(data[i * 8:(i * 8 + 8)]) # join all the letters to form the message. message = [chr(int(''.join(i), 2)) for i in message] message = ''.join(message) message_label = Label(app, text=message, bg='lavender', font=("Times New Roman", 10)) message_label.place(x=30, y=400)
def UploadInfo(self): #ticket = str(self.ticket_number.get())+".PNG" #print(ticket) try: self.path = "D:/Apache Software Foundation/Tomcat 9.0/webapps/cenrayid/WEB-INF/classes/photo/" + self.ticket_number.get( ) + ".jpg" #path="/Photo/"+str(self.ticket_number.get())+".png" #self.img = ImageTk.PhotoImage(Image.open(path)) self.img = Image.open(self.path) self.img = self.img.resize((100, 100), Image.ANTIALIAS) self.img = ImageTk.PhotoImage(self.img) ''' self.img=PhotoImage(file="D:/TimeKeeper_stuffs/Photo/"+self.ticket_number.get()+".png") self.img=self.img.zoom(25,25) self.img=self.img.subsample(50) ''' Label(self.root, image=self.img).place(x=50, y=450) except Exception as e: #print(e) Label(self.root, text="unable to load image").place(x=50, y=450) self.dictionarydata = {} #*********************************************************************** # created object of class DataBase; # if we want to use different database then just change DataBase class self.db = DataBase() #************************************************************************ #print(self.ticket_number.get()) self.dictionarydata = self.db.load(self.ticket_number.get()) #print(self.dictionarydata) if (self.dictionarydata): self.fullname.set(self.dictionarydata['full_name']) self.department.set(self.dictionarydata['department']) #self.cardLost.set(self.dictionarydata['card_lost']) self.memo.set(self.dictionarydata['reason_for_memo']) self.remark.insert('end', self.dictionarydata['remark']) self.shift.set(self.dictionarydata['shift']) self.dept_code.set(self.dictionarydata['department_code']) return True else: return False
def cropy(): global panel x = openfn() image_obj = Image.open(x) cropped_image = image_obj.crop((161, 166, 706, 1050)) img = cropped_image.resize((400, 500), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO") def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': cropped_image.save('crop.JPEG') threading.Timer(5.0, saveb).start()
def blackwhite(): global panel x = openfn() color_image = Image.open(x) bw = color_image.convert('L') img = bw.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO") def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': bw.save('blackandwhite.jpg') threading.Timer(5.0, saveb).start()
def mirror(): global panel x = openfn() image_obj = Image.open(x) rotated_image = image_obj.transpose(Image.FLIP_LEFT_RIGHT) img = rotated_image.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO") def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': rotated_image.save('mirror.JPEG') threading.Timer(5.0, saveb).start()
def blur(): global panel x = openfn() img = Image.open(x) im = img.filter(ImageFilter.BLUR) img = im.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img #panel.image = NONE panel.pack(side="top", fill="both", expand="NO") def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': im.save('blur.jpg') threading.Timer(5.0, saveb).start()
def sharpen(): global panel x = openfn() im = Image.open(x) im_sharp = im.filter(ImageFilter.SHARPEN) img = im_sharp.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO") #im_sharp.save('image_sharpened.jpg', 'JPEG') #im_sharp.show() def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': im_sharp.save('sharpen.jpg') threading.Timer(5.0, saveb).start()
def brightness(): global panel x = openfn() im = Image.open(x) im3 = ImageEnhance.Brightness(im) im2 = im3.enhance(2.0) img = im2.resize((1000, 800), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack() #panel.image = NONE def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': im3.enhance(2.0).save("brightness.jpg") threading.Timer(5.0, saveb).start()
def rotate(): global panel x = openfn() image_obj = Image.open(x) rotated_image = image_obj.rotate(90) img = rotated_image.resize((1250, 900), Image.ANTIALIAS) img = ImageTk.PhotoImage(img) panel = Label(root, image=img) panel.image = img panel.pack(side="top", fill="both", expand="NO") #rotated_image.save(saved_location) #rotated_image.show() def saveb(): MsgBox = tk.messagebox.askquestion('SAVE', 'do you want to save the img', icon='warning') if MsgBox == 'yes': rotated_image.save('rotate.JPEG') threading.Timer(5.0, saveb).start()
def __init__(self, master=None): super().__init__(master, padx=12, pady=3) if getattr(sys, 'frozen', False): self.baseDir = os.path.dirname(sys.executable) else: self.baseDir = os.path.dirname(os.path.realpath(__file__)) self.loadConfig() self.master = master self.queue = queue.initQueue() self.grid() rowIndex = 0 self.logoImage = ImageTk.PhotoImage(Image.open('logo.png')) self.logoLabel = tk.Label(self, image=self.logoImage) self.logoLabel.grid(row=rowIndex, column=0, columnspan=5) rowIndex += 1 self.deckNameLabel = tk.Label(self, text='Deckname') self.deckNameLabel.grid(row=rowIndex, column=0, sticky=tk.W) self.deckNameEntry = tk.Entry(self, width=60) self.deckNameEntry.grid(row=rowIndex, column=1, columnspan=3, stick=tk.W) self.deckNameEntry.insert(0, 'Deck') rowIndex += 1 self.inputLabel = tk.Label(self, text='File or URL') self.inputLabel.grid(row=rowIndex, column=0, sticky=tk.W) self.inputEntry = tk.Entry(self, width=60) self.inputEntry.grid(row=rowIndex, column=1, columnspan=3, sticky=tk.W) self.inputButton = tk.Button(self, text='Browse', command=self.openFile) self.inputButton.grid(row=rowIndex, column=4, sticky=tk.E) rowIndex += 1 self.outputLabel = tk.Label(self, text='Output folder (optional)') self.outputLabel.grid(row=rowIndex, column=0, sticky=tk.W) self.outputEntry = tk.Entry(self, width=60) self.outputEntry.grid(row=rowIndex, column=1, columnspan=3, sticky=tk.W) self.outputEntry.insert(0, self.config['outputFolder']) self.outputButton = tk.Button(self, text='Browse', command=self.openFolder) self.outputButton.grid(row=rowIndex, column=4, sticky=tk.E) rowIndex += 1 self.imgurLabel = tk.Label(self, text='ImgurID (optional)') self.imgurLabel.grid(row=rowIndex, column=0, sticky=tk.W) self.imgurEntry = tk.Entry(self, width=60) self.imgurEntry.grid(row=rowIndex, column=1, columnspan=3, sticky=tk.W) if self.config['imgurId']: self.imgurEntry.insert(0, self.config['imgurId']) self.imgurEntry.config(state='disabled') rowIndex += 1 self.dropboxLabel = tk.Label(self, text='Dropbox Token(optional)') self.dropboxLabel.grid(row=rowIndex, column=0, sticky=tk.W) self.dropboxEntry = tk.Entry(self, width=60) self.dropboxEntry.grid(row=rowIndex, column=1, columnspan=3, sticky=tk.W) if self.config['dropboxToken']: self.dropboxEntry.insert(0, self.config['dropboxToken']) self.dropboxEntry.config(state='disabled') rowIndex += 1 self.basicsLabel = tk.Label(self, text='Basic lands') self.basicsLabel.grid(row=rowIndex, column=0, sticky=tk.W) basicsOptions = ('guru', 'unstable', 'alpha', 'core', 'guay') self.basicsVar = tk.StringVar() self.basicsVar.set(self.config['basicSet']) self.basicsMenu = tk.OptionMenu(self, self.basicsVar, *basicsOptions) self.basicsMenu.grid(row=rowIndex, column=1, columnspan=2, sticky=tk.W) rowIndex += 1 self.hiresVar = tk.IntVar() self.hiresVar.set(int(self.config['hires'])) self.hiresCheckbutton = tk.Checkbutton(self, text='High Resolution', variable=self.hiresVar) self.hiresCheckbutton.grid(row=rowIndex, column=0, sticky=tk.W) self.hiresVar.trace('w', self.hiresVarCallback) self.reprintsVar = tk.IntVar() self.reprintsVar.set(int(self.config['reprints'])) self.reprintsCheckbutton = tk.Checkbutton(self, text='Reprints', variable=self.reprintsVar) self.reprintsCheckbutton.grid(row=rowIndex, column=1, sticky=tk.W) self.nocacheVar = tk.IntVar() self.nocacheVar.set(int(self.config['nocache'])) self.nocacheCheckbutton = tk.Checkbutton(self, text='No cache', variable=self.nocacheVar) self.nocacheCheckbutton.grid(row=rowIndex, column=2, sticky=tk.W) self.imgurVar = tk.IntVar() self.imgurVar.set(int(self.config['imgur'])) self.imgurCheckbutton = tk.Checkbutton(self, text='Imgur Upload', variable=self.imgurVar) self.imgurCheckbutton.grid(row=rowIndex, column=3, sticky=tk.W) self.imgurVar.trace('w', self.imgurVarCallback) self.updateImgurEntry() self.dropboxVar = tk.IntVar() self.dropboxVar.set(int(self.config['dropbox'])) self.dropboxCheckbutton = tk.Checkbutton(self, text='Dropbox Upload', variable=self.dropboxVar) self.dropboxCheckbutton.grid(row=rowIndex, column=4, sticky=tk.W) self.dropboxVar.trace('w', self.dropboxVarCallback) self.updateDropboxEntry() rowIndex += 1 self.progressLabel = tk.Label(self, text='Ready') self.progressLabel.grid(row=rowIndex, column=0, columnspan=4, sticky=tk.W) self.generateButton = tk.Button(self, text='Generate', command=self.generate) self.generateButton.grid(row=rowIndex, column=4, sticky=tk.E) self.processQueue()
# start button created startb = Button(window1, text="START", command=start_fun, font=("Arial", 25), bg="orange", fg="blue", borderwidth=3, relief="raised") startb.place(x=130, y=590) # image on the main window path = "Images/front.png" # Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object. img1 = ImageTk.PhotoImage(Image.open(path)) # The Label widget is a standard Tkinter widget used to display a text or image on the screen. panel = tk.Label(window1, image=img1) panel.place(x=320, y=200) # function created for exiting def exit_win(): if mbox.askokcancel("Exit", "Do you want to exit?"): window1.destroy() # exit button created exitb = Button(window1, text="EXIT", command=exit_win,
def rolling_dice(): image1 = ImageTk.PhotoImage(Image.open(random.choice(dice))) # update image label1.configure(image=image1) # keep a reference label1.image = image1
# Adding label into the frame l0 = tkinter.Label(root, text="") l0.pack() # adding label with different font and formatting l1 = tkinter.Label(root, text="Hello...!", fg="light green", bg="dark green", font="Helvetica 16 bold italic") l1.pack() # images dice = ['die1.png', 'die2.png', 'die3.png', 'die4.png', 'die5.png', 'die6.png'] # simulating the dice with random numbers between 0 to 6 and generating image image1 = ImageTk.PhotoImage(Image.open(random.choice(dice))) # construct a label widget for image label1 = tkinter.Label(root, image=image1) label1.image = image1 # packing a widget in the parent widget label1.pack(expand=True) # function activated by button def rolling_dice(): image1 = ImageTk.PhotoImage(Image.open(random.choice(dice))) # update image label1.configure(image=image1) # keep a reference
from tkinter import * from pil import Image, ImageTk root = Tk() root.option_add("*Font", "consolas 25") images = ['phumin-1', 'phumin-2', 'phumin-3'] imag_list = [] for i, ing in enumerate(images): imag_list.append(ImageTk.PhotoImage(Image.open(f'{ing}.jpg'))) lbl = Label(image=imag_list[i]) lbl.grid(row=0, column=i) Label(root, text=f'{ing}.jpg').grid(row=1, column=i) root.mainloop()