def create_image_button(canvas: Canvas, window: Tk, name: str) -> Canvas: global NUMBER_OF_IMAGE_BUTTON NUMBER_OF_IMAGE_BUTTON += 1 ima = PhotoImage(RESOURCE_DIR_PATH + "images/" + name + ".png") ima.zoom(window.winfo_screenheight() / (6 * ima.height()), window.winfo_screenheight() / (6 * ima.height())) i = NUMBER_OF_IMAGE_BUTTON % 3 if NUMBER_OF_IMAGE_BUTTON % 3 == 0: i = 3 return canvas.create_image(window.winfo_screenwidth() * i / 4, window.winfo_screenheight() * math.ceil(NUMBER_OF_IMAGE_BUTTON / 3) / 3, image=ima, anchor=CENTER)
def get_image(location, width, height): image = PhotoImage(data=Resource(location).resource) orig_width = image.width() orig_height = image.height() image = image.zoom(width, height) image = image.subsample(orig_width, orig_height) return image
def PlaceBtn(imgfile,_row,_col, _callback,lbl): photo1 = PhotoImage(file=imgfile) photo1 = photo1.zoom(3) photo1 = photo1.subsample(5) btn = Button(self, text="Up",command = lambda: _callback(lbl), image=photo1, borderwidth=0) btn.image = photo1 btn.grid(row=_row, column=_col)
def __LoadInterface(self): """ Load GUI interface from json instead of live""" standard.Log("Loading GUI interface...") interface = standard.LoadInterface() for n, i in enumerate(interface): extra = {} if i["x"] < 0: x = self.root.winfo_screenwidth()+i["x"] else: x = i["x"] if i["y"] < 0: y = self.root.winfo_screenheight()+i["y"] else: y = i["y"] if (i["type"] == "label"): widget = Label( self.__Root, width = i["width"], height = i["height"], bg=self.__Configuration["pixel.pixel"]["background colour"], anchor=W, justify=LEFT) extra["module"] = i["module"] elif i["type"] == "button": widget = Button( self.__Root, width = i["width"], height = i["height"], bg=self.__Configuration["pixel.pixel"]["background colour"]) #relief="flat") elif i["type"] == "image": widget = Label( self.__Root, width = i["width"], height = i["height"], bg=self.__Configuration["pixel.pixel"]["background colour"], anchor=W, justify=LEFT) if "text" in i: widget.config( text = i["text"], font = (i["font"], i["font size"]), fg=i["font colour"]) elif "image" in i: photo = PhotoImage(file = i["image"]) extra["image"] = i["image"] if "zoom" in i: photo = photo.zoom(i["zoom"]) extra["zoom"] = i["zoom"] if "subsample" in i: photo = photo.subsample(i["subsample"]) extra["subsample"] = i["subsample"] widget.config(image = photo) widget.image = photo widget.place(x = i["x"], y = i["y"]) self.__Interface.append((i["tag"], widget, extra)) standard.Log("Loading GUI interface... Done")
class Reaction(): def __init__(self): self.text = "" self.id = 'base' self.face = PhotoImage(file="img/base.png") self.face = self.face.zoom(1, 1) self.face = self.face.subsample(1, 1) def __call__(self, reaction): self.face = reaction.face def __eq__(self, obj): return self.id == obj.id
def _icon_scale(self, icon: tk.PhotoImage) -> tk.PhotoImage: ''' Rescale icon. Args: icon: icon to be rescaled Returns: tk.PhotoImage: rescaled icon ''' if self.scaling[0] != 1: icon = icon.zoom(self.scaling[0], self.scaling[0]) if self.scaling[1] != 1: icon = icon.subsample(self.scaling[1], self.scaling[1]) return icon
def load_frames(self, path, zoom, subsample): self._frames = [] i = 0 try: while i < 100: fformat = "gif -index " + str(i) photoframe = PhotoImage(file=path, format=fformat) photoframe = photoframe.zoom(zoom) photoframe = photoframe.subsample(subsample) self._frames.append(photoframe) i += 1 except Exception as inst: if (inst.args[0] == 'no image data for this index'): pass self._last_index = len(self._frames)
def draw_image(cv, url): global withpil, im root.title("Python Image Viewer - {0}".format(url)) if withpil: im = Image.open(url) imsize = im.size cvsize = get_objsize(cv) ratio, newpos, newsize = cal_fitsize(imsize, cvsize) imresize = im.resize(newsize) pi = ImageTk.PhotoImage(image=imresize) else: pi = PhotoImage(file=url) #wrap with pillow resized im imsize = pi.width(), pi.height() cvsize = get_objsize(cv) ratio, newpos, newsize = cal_fitsize(imsize, cvsize) pi = pi.zoom(ratio) # placing in canvas cv.delete(ALL) cv.image = pi #https://stackoverflow.com/a/37214188 cv.create_image(newpos[0], newpos[1], anchor=NW, image=pi) return 1
def PhotoImageFromLink(link, width=None, height=None, scale=None): base64_data = downloadImage(link) image = PhotoImage(data=base64_data) (old_w, old_h) = (image.width(), image.height()) if scale != None: width = int(old_w * scale) height = int(old_h * scale) (target_w, target_h) = (width, height) if (target_w != None and target_h != None): x_common = math.gcd(target_w, old_w) x_zoom = int(target_w / x_common) x_sub = int(old_w / x_common) y_common = math.gcd(target_h, old_h) y_zoom = int(target_h / y_common) y_sub = int(old_h / y_common) image = image.zoom(x_zoom, y_zoom) image = image.subsample(x_sub, y_sub) return image
class Window: def __init__(self, window): self.window = window self.random_list = [] self.color = "black" self.dark_image = PhotoImage(file="dark_mode.png") self.dark_image = self.dark_image.zoom(1) self.dark_image = self.dark_image.subsample(30) self.canvas = Canvas(self.window, bg="#f0ffff") self.canvas.place(relx=0, relwidth=1, relheight=0.80) self.display_options() def display_options(self): lower_frame = tk.Frame(self.window, bg="#1b3945") lower_frame.place(relx=0, rely=0.8, relwidth=1, relheight=0.2) algorithm_label = tk.Label(lower_frame, text="Algorithm", width=20) algorithm_label.place(x=40, y=20) combo_algorithm = ttk.Combobox(lower_frame, values=[ "Bubble sort", "Selection sort", "Insertion sort", "Cocktail shaker sort", "Shell sort" ], font=(8)) combo_algorithm.place(x=40, y=60) combo_algorithm.config(font=("Helvetica"), width=16) combo_algorithm.current(0) min_value = tk.Label(lower_frame, text="Min. Value", width=20) min_value.place(x=240, y=20) min_value_number = tk.Scale(lower_frame, from_=1, to=1000, orient=tk.HORIZONTAL, width=5) min_value_number.place(x=260, y=60) max_value = tk.Label(lower_frame, text="Max. Value", width=20) max_value.place(x=440, y=20) max_value_number = tk.Scale(lower_frame, from_=1, to=1000, orient=tk.HORIZONTAL, width=5) max_value_number.place(x=460, y=60) speed = tk.Label(lower_frame, text="Speed", width=19) speed.place(x=640, y=20) speed_var = tk.Scale(lower_frame, from_=1, to=5, orient=tk.HORIZONTAL, width=5) speed_var.place(x=660, y=60) new_info_btn = tk.Button( lower_frame, text="Generate graph", activebackground="#468499", width=12, command=lambda: self.generate_info(min_value_number.get( ), max_value_number.get(), combo_algorithm.get())) new_info_btn.place(x=825, y=15) sort_items = tk.Button(lower_frame, text="Sort", activebackground="#468499", width=12, command=lambda: self.select_algorithm( speed_var.get(), combo_algorithm.get())) sort_items.place(x=825, y=53) delete_btn = tk.Button(lower_frame, text="Delete all", activebackground="#468499", width=12, command=self.delete_all) delete_btn.place(x=825, y=90) img_label = tk.Label(lower_frame, background="white", image=self.dark_image) img_label.place(x=955, y=45) img_label.bind('<Button-1>', lambda x: self.dark_screen(lower_frame)) def comparisons_info(self, comp_value): self.canvas.create_text(20, 500, anchor="sw", text="Comparisons", fill=self.color) self.canvas.create_text(130, 500, anchor="sw", text=comp_value, fill=self.color) def speed_values(self, speed): if speed == 1: return 0.4 elif speed == 2: return 0.3 elif speed == 3: return 0.2 elif speed == 4: return 0.1 else: return 0.08 def dark_screen(self, lower_frame): if self.color == "black": self.canvas.config(bg="#666666") lower_frame.config(bg="#333333") self.canvas.update_idletasks() self.color = "white" else: self.canvas.config(bg="#f0ffff") lower_frame.config(bg="#1b3945") self.canvas.update_idletasks() self.color = "black" def select_algorithm(self, speed, option): if option == "Bubble sort": bubble_sort(self.speed_values(speed), self.random_list, 0, self.draw_info, self.final_animation) elif option == "Selection sort": selection_sort(self.speed_values(speed), self.random_list, 0, self.draw_info, self.final_animation) elif option == "Insertion sort": insertion_sort(self.speed_values(speed), self.random_list, 0, self.draw_info, self.final_animation) elif option == "Cocktail shaker sort": cocktail_sort(self.speed_values(speed), self.random_list, 0, self.draw_info, self.final_animation) elif option == "Shell sort": shell_sort(self.speed_values(speed), self.random_list, 0, self.draw_info, self.final_animation) def final_animation(self, comp_value): for x in range(len(self.random_list)): time.sleep(0.03) self.draw_info(comp_value, [ "#ff7f50" if i <= x else "#4ca3dd" if i == x + 1 else "#badd99" for i in range(len(self.random_list)) ]) #self.draw_info(["#f3d3a5" if i <= x else "#4e2c7f" if i == x+1 else "#badd99" fothemer i in range(len(self.random_list))]) def delete_all(self): self.canvas.delete("all") def generate_info(self, min_value, max_value, algorithm): self.canvas.delete("all") self.random_list.clear() if min_value > max_value: mBox.showerror("ERROR", "Value error") return for i in range(24): number = random.randint(min_value, max_value) self.random_list.append(number) max_value = max(self.random_list) temp_list = [] for i in self.random_list: height_value = int(i * 450 / max_value) #max_value = 450 -> i? if height_value <= 9: temp_list.append((i, 9)) continue temp_list.append((i, height_value)) #[(1, 10), (32, 300)] self.random_list = temp_list print(self.random_list) return self.draw_info( 0, ["#ffa500" for i in range(len(self.random_list))]) def draw_info(self, comp_value, color): self.canvas.delete("all") self.comparisons_info(comp_value) x = 20 y = 50 for key, value in enumerate(self.random_list): self.canvas.create_rectangle(x, value[1], y, 10, fill=color[key]) self.canvas.create_text(x, value[1] + 20, anchor="sw", text=value[0], fill=self.color) x += 40 y += 40 self.window.update_idletasks()
def get_image_for_sprite(sprite): if not sprite.valid: return None height = 24 width = 16 def draw_sprite_into_gif(add_palette_color, set_pixel_color_index): def drawsprite(spr, pal_as_colors, offset): for y, row in enumerate(spr): for x, pal_index in enumerate(row): if pal_index: color = pal_as_colors[pal_index - 1] set_pixel_color_index(x + offset[0], y + offset[1], color) add_palette_color(16, (40, 40, 40)) shadow = [ [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0], ] drawsprite(shadow, [16], (2, 17)) palettes = sprite.decode_palette() for i in range(15): add_palette_color(i + 1, palettes[0][i]) body = sprite.decode16(0x4C0) drawsprite(body, list(range(1, 16)), (0, 8)) head = sprite.decode16(0x40) drawsprite(head, list(range(1, 16)), (0, 0)) def make_gif(callback): gif_header = b'GIF89a' gif_lsd = bytearray(7) gif_lsd[0] = width gif_lsd[2] = height gif_lsd[ 4] = 0xF4 # 32 color palette follows. transparant + 15 for sprite + 1 for shadow=17 which rounds up to 32 as nearest power of 2 gif_lsd[5] = 0 # background color is zero gif_lsd[6] = 0 # aspect raio not specified gif_gct = bytearray(3 * 32) gif_gce = bytearray(8) gif_gce[0] = 0x21 # start of extention blocked gif_gce[1] = 0xF9 # identifies this as the Graphics Control extension gif_gce[2] = 4 # we are suppling only the 4 four bytes gif_gce[3] = 0x01 # this gif includes transparency gif_gce[4] = gif_gce[5] = 0 # animation frrame delay (unused) gif_gce[6] = 0 # transparent color is index 0 gif_gce[7] = 0 # end of gif_gce gif_id = bytearray(10) gif_id[0] = 0x2c # byte 1,2 are image left. 3,4 are image top both are left as zerosuitsamus gif_id[5] = width gif_id[7] = height gif_id[9] = 0 # no local color table gif_img_minimum_code_size = bytes( [7] ) # we choose 7 bits, so that each pixel is represented by a byte, for conviennce. clear = 0x80 stop = 0x81 unchunked_image_data = bytearray(height * (width + 1) + 1) # we technically need a Clear code once every 125 bytes, but we do it at the start of every row for simplicity for row in range(height): unchunked_image_data[row * (width + 1)] = clear unchunked_image_data[-1] = stop def add_palette_color(index, color): gif_gct[3 * index] = color[0] gif_gct[3 * index + 1] = color[1] gif_gct[3 * index + 2] = color[2] def set_pixel_color_index(x, y, color): unchunked_image_data[y * (width + 1) + x + 1] = color callback(add_palette_color, set_pixel_color_index) def chunk_image(img): for i in range(0, len(img), 255): chunk = img[i:i + 255] yield bytes([len(chunk)]) yield chunk gif_img = b''.join([gif_img_minimum_code_size] + list(chunk_image(unchunked_image_data)) + [b'\x00']) gif = b''.join( [gif_header, gif_lsd, gif_gct, gif_gce, gif_id, gif_img, b'\x3b']) return gif gif_data = make_gif(draw_sprite_into_gif) image = PhotoImage(data=gif_data) return image.zoom(2)
class BugApp(tk.Frame): def __init__(self, master=None): # create race self.race = Race() #gets all bugs in buglist document and adds to list self.race.add_bugs(get_bugs()) tk.Frame.__init__(self, master) self.pack() self.addWidgets() self.zoomAmount = 4 def addWidgets(self): # create and zoom to map image self.create_img() self.zoom_image() # set up canvas size self.canvas = Canvas(self, width=self.img.width(), height=self.img.height(), bg="#000000") # set up location of img on canvas self.canvas.create_image( (self.img.width() // 2, self.img.height() // 2), image=self.img, state="normal") # pack canvas into window self.canvas.pack() # initial time display self.bug_clock() def print_bugs(self): for i in range(0, len(self.race.bugLocs)): if i == 0: self.img.put( "#00FF00", (self.race.bugLocs[i][0] + 2, self.race.bugLocs[i][1] + 2)) elif i == 1: self.img.put( "#FF0000", (self.race.bugLocs[i][0] + 2, self.race.bugLocs[i][1] + 2)) elif i == 2: self.img.put( "#0000FF", (self.race.bugLocs[i][0] + 2, self.race.bugLocs[i][1] + 2)) elif i == 3: self.img.put( "#8000FF", (self.race.bugLocs[i][0] + 2, self.race.bugLocs[i][1] + 2)) def print_state(self): for i in range(0, self.race.mazy.xLen): for j in range(0, self.race.mazy.yLen): # if wall if self.race.mazy.grid[i][j] == 1: self.img.put("#000000", (i + 2, j + 2)) # if open space if self.race.mazy.grid[i][j] == 0: self.img.put("#ffffff", (i + 2, j + 2)) # if exit if self.race.mazy.grid[i][j] == 3: self.img.put("#ffffff", (i + 2, j + 2)) def bug_clock(self): print("bug clockin' time = ", self.race.timer) self.race.bug_actions() self.create_img() self.zoom_image() self.canvas.create_image( (self.img.width() // 2, self.img.height() // 2), image=self.img, state="normal") # increment race timer self.race.timer += 1 self.after(500, self.bug_clock) def create_img(self): # set width and height of picture to make. add a row for black on each side width = self.race.mazy.xLen + 2 height = self.race.mazy.yLen + 2 # create photo image at width and height self.img = PhotoImage(width=width, height=height) self.print_state() self.print_bugs() def zoom_image(self): self.img = self.img.zoom(4, 4) #self.zoomAmount, self.zoomAmount)
def __init__(self, parent, controller, queue): Frame.__init__(self, parent) self.controller = controller self.queue = queue self.display_time_count = 0 self.WIFI_on = False self.last_temp_reading = -100 ''' when Off Manual Program Thermostat is clicked ''' def OffBtnClick(): if (OffBtn["text"] == "Off"): OffBtn["text"] = "Manual" UpTempBtn["state"]="normal" DnTempBtn["state"]="normal" SetTempLbl["state"]="normal" PrgBtn["state"]="disabled" elif OffBtn["text"] == "Manual": OffBtn["text"] = "Thermostat" UpTempBtn["state"]="disabled" DnTempBtn["state"]="disabled" SetTempLbl["state"]="normal" PrgBtn["state"]="normal" elif OffBtn["text"] == "Thermostat": OffBtn["text"] = "Off" UpTempBtn["state"]="disabled" DnTempBtn["state"]="disabled" SetTempLbl["state"]="normal" PrgBtn["state"]="disabled" FunctLbl["text"] = OffBtn["text"] self.OffBtnClick = OffBtnClick ''' when Program Button is clicked ''' def PrgBtnClick(): controller.show_frame("PagePrg") def UpTempBtnClick(): temp = float(SetTempLbl["text"][:-1]) SetTempLbl["text"] = str(temp+1.0) + "°" def DnTempBtnClick(): temp = float(SetTempLbl["text"][:-1]) SetTempLbl["text"] = str(temp-1.0) + "°" def PlaceTimeNow(_text, _row,_col): timeStyle = Style () timeStyle.configure("Time.TLabel", font = ('Helvetica','15','bold')) TimeLbl = Label(self, text=_text, style="Time.TLabel") TimeLbl.grid(row=_row,column=_col) return TimeLbl ''' SepLbl - First Row ''' sepStyle = Style () sepStyle.configure("Sep.TLabel", font = ('Helvetica','15','bold')) SepLbl = Label(self, text=" ", width=2, style = "Sep.TLabel") SepLbl.grid(row=0, column=0) ''' OffBtn ''' photo1 = PhotoImage(file="rightarrow.gif") photo1 = photo1.zoom(2) photo1 = photo1.subsample(5) OffBtn = Button(self, text="Thermostat", image=photo1, borderwidth=0, command=OffBtnClick) OffBtn.image = photo1 OffBtn.grid(row=1, column=1 ) self.OffBtn = OffBtn ''' FunctLbl ''' functStyle = Style () functStyle.configure("funct.TLabel", font = ('Helvetica','14','bold'), foreground="black") FunctLbl = Label(self, text=" ", width=10, style="funct.TLabel") FunctLbl["text"] = OffBtn["text"] FunctLbl.grid(row=1, column=2, columnspan=2) tempStyle = Style () tempStyle.configure("Temp.TLabel", font = ('Helvetica','40','bold'), foreground="red") TempLbl = Label(self, text="20.0°", style="Temp.TLabel") TempLbl.grid(row=2,column=2,columnspan=2) self.Temp = TempLbl # to be used by read_sensor ''' Flame ''' flameImg = PhotoImage(file="flame.gif") flameImg = flameImg.subsample(4) flameBtn = Button(self, text="Up", image=flameImg, borderwidth=0) # flameBtn.grid(row=3, column=2) flameBtn.image = flameImg self.flameBtn = flameBtn ''' Animated Flame ''' ani_flame_icon = AnimatedGIF(master=self, path = "ani_flame.gif",zoom=2, subsample=5) ani_flame_icon._delay = 100 # update every 100 msec # ani_flame_icon.grid(row=3,column=1) self.ani_flame_icon = ani_flame_icon ''' Animated Flame2 ''' ani_flame_icon2 = AnimatedGIF(master=self, path = "ani_flame.gif",zoom=2, subsample=5) ani_flame_icon2._delay = 100 # update every 100 msec ani_flame_icon2.grid(row=3,column=2) self.ani_flame_icon2 = ani_flame_icon2 ''' Animated Flame3 ''' ani_flame_icon3 = AnimatedGIF(master=self, path = "ani_flame.gif",zoom=2, subsample=5) ani_flame_icon3._delay = 100 # update every 100 msec # ani_flame_icon3.grid(row=3,column=3) self.ani_flame_icon3 = ani_flame_icon3 ''' SepLbl ''' SepLbl = Label(self, text=" ", width=2) SepLbl.grid(row=3, column=4) ''' UpTempBtn ''' photo1 = PhotoImage(file="up.gif") photo1 = photo1.zoom(4) photo1 = photo1.subsample(5) UpTempBtn = Button(self, text="Up", command=UpTempBtnClick, image=photo1, borderwidth=0) UpTempBtn.grid(row=1, column=5) UpTempBtn.image = photo1 ''' DnTempBtn ''' photo2 = PhotoImage(file="dn.gif") photo2 = photo2.zoom(4) photo2 = photo2.subsample(5) DnTempBtn = Button(self, text="Dno", command=DnTempBtnClick, image=photo2, borderwidth=0) DnTempBtn.grid(row=3, column=5) DnTempBtn.image = photo2 ''' SetTempLbl ''' SetTempStyle = Style () SetTempStyle.configure("SetTemp.TLabel", font = ('Helvetica','20','bold'), foreground="blue") SetTempLbl = Label(self, text="22.0°", style="SetTemp.TLabel") SetTempLbl.grid(row=2,column=5) self.SetTemp = SetTempLbl ''' SepLbl ''' SetTempStyle = Style () SetTempStyle.configure("SetTemp.TLabel", font = ('Helvetica','20','bold'), foreground="blue") SepRowLbl = Label(self, text=" ", style="SetTemp.TLabel") SepRowLbl.grid(row=4,column=3) ''' PrgBtn ''' photo3 = PhotoImage(file="settings.gif") photo3 = photo3.zoom(3) photo3 = photo3.subsample(5) PrgBtn = Button(self, text="Prg", command=PrgBtnClick, image=photo3, borderwidth=0) PrgBtn.grid(row=2, column=6) PrgBtn.image = photo3 self.PrgBtn = PrgBtn ''' WIFI ''' WIFI_icon = AnimatedGIF(master=self, path = "WIFI_red.gif", subsample=8) WIFI_icon.grid(row=4,column=6) self.WIFI_icon = WIFI_icon ''' Time ''' placeTimeNow = PlaceTimeNow(time.strftime("%H:%M:%S"), 4,2) placeTimeNow.after(1000, self.display_time) # every second self.placeTimeNow = placeTimeNow self.read_sensor()
res = requests.get(api_url, params=params) data = res.json() data_output(data_organizer(data_fetch(data))) #zip code id (xxxxxxx) goes here except IOError: print('no internet') # test print (weatherid) tempimg= PhotoImage(file="id.gif") imgtemp = Label(image=tempimg) #temp image tempimg=PhotoImage(file="id.gif")#finding the image make sure its in same folder and is a gif tempweat = tempimg.zoom(3, 3) #this new image is 3x the original tempweat = tempimg.subsample(2,2) imgtemp = Label(image=tempweat) imgtemp.grid(row=0, column=0) #temp=Label(text='Temp ', font=("Courier", 28, 'bold')) #temp.grid(row=0, column=5) #created by AP #wind image windimg=PhotoImage(file="id2.gif") windweat = windimg.zoom(3, 3) #this new image is 3x the original windweat = windimg.subsample(2,2)
string = text = "WELCOME, I am Talk Bob." + "\n" + "How would you like to converse with me" def withmic(): import main_asli def withoutmic(): import dep_mute.main_muted upperFrame = tk.Frame(window, bg='turquoise4', width=850, height=400) lowerFrame = tk.Frame(window, bg='turquoise4', width=850, height=200) photo = PhotoImage(file="logo.png") photo.zoom(120, 120) #photo = PhotoImage(file = r"logo.png") #button=tk.Button(window, text = 'Click Me !', image = photo).pack() button = tk.Button(upperFrame, text='PYTHON MAYHEM', height=180, width=130, image=photo, bg='white') text = tk.Label(upperFrame, text=string, fg="white", bg='turquoise4',
def TodayStallMenu(key, stallName, op): #TODAY MENU #Srishti and Bernard kill_all_children(root) main_Panel = backgroundSet() stall = rf.retrieveAllStall() button_Operating = tk.Button(main_Panel, text="View Operating Hrs", command=partial(refreshTodayMenu, key, stallName), font=("Bookman Old Style", 15), foreground="white", background="black", height=1) #Button to display operating hours button_Operating.place(x=22, y=80) if op != "0": #To check if operating hour button is clicked hr = rf.DisplayOperatingHrs(key, stall) label_OperatingHrs = tk.Label(main_Panel, text="Operating Hrs: " + hr, font=("Bookman Old Style", 15, "bold"), background="black", foreground="white") label_OperatingHrs.place(x=2, y=80) button_Operating.place_forget() rawImg_Back = tk.PhotoImage(file="./Gui_Images/back.gif") imageBack = rawImg_Back.subsample(25, 25) w = imageBack.width() h = imageBack.height() button_Back = tk.Button(main_Panel, width=w, height=w, image=imageBack, command=lambda: ViewToday()) #Back Button button_Back.image = imageBack button_Back.pack() button_Back.place(relx=1, rely=1, anchor="se") label_SelectedStall = tk.Label( main_Panel, text=stallName + "'s Menu for the day", font=("Bookman Old Style", 20, "bold"), foreground="white", background="#654321", padx=5, pady=5, relief="groove") #Heading for stall's menu based on the date and time label_SelectedStall.grid(row=0, column=2, columnspan=5, pady=10, sticky="w") filename = './Images/' + key + ".png" rawImg = PhotoImage(file=filename) nImg = rawImg.zoom(1, 1) w = nImg.width() h = nImg.height() img_Selected = tk.Label(main_Panel, image=nImg, width=w, height=h, relief="solid") img_Selected.image = nImg img_Selected.grid(row=2, column=1, rowspan=4, pady=100, padx=50, sticky="n") #Stall's logo menu = rf.retrieveAllMenu() menuList = rf.displayMenuBySystem(key, menu) if not menuList: #Error Handling if no menu, display this label_Unavailable = tk.Label( main_Panel, text="There is no menu available at this timing", font=("Bookman Old Style", 20), foreground="white", background="black", padx=5, pady=5, relief="flat") label_Unavailable.grid(row=4, column=2, columnspan=2, sticky="n") else: #Error Handling if got menu, then display the menu button_Waiting = tk.Button(main_Panel, text="Calculate waiting time", font=("Bookman Old Style", 15), foreground="white", background="#654321", padx=5, pady=5, command=lambda: waitingTime(key, stallName)) button_Waiting.grid(row=2, column=1, rowspan=4, sticky="s") count = 1 rowcount = 2 for menuKey, itemInfo in menuList.items(): filename = './Menu_Images/' + itemInfo[0] + ".png" rawImg = PhotoImage(file=filename) nImg = rawImg.subsample(1, 1) label_Menu = tk.Label(main_Panel, width=200, height=150, anchor="center", image=nImg, background="white") #Menu's image label_Menu.image = nImg label_Name = tk.Label(main_Panel, width=24, anchor="n", font="Verdana 8 bold", text=itemInfo[0] + " $" + itemInfo[2], background="black", foreground="white") #Menu's name colcount = 0 if count > 3: #To position and organise menu item if count % 3 == 1: rowcount += 1 colcount = 2 elif count % 3 == 2: rowcount = rowcount colcount = 3 elif count % 3 == 0: rowcount = rowcount colcount = 4 count += 1 else: colcount = count + 1 rowcount = 2 count += 1 label_Menu.grid(row=rowcount, column=colcount, pady=18, padx=20, sticky="s") label_Name.grid(row=rowcount, column=colcount, padx=0, sticky="s")