def initUI(self): self.master.title('Absolute Posintioning') self.pack(fill=BOTH, expand=1) # 设置背景颜色 Style().configure('TFrame', backgroud='#ccc') # 我们从当前工作目录中的图像创建图像对象和照片图像对象 bard = Image.open( r'/Users/badboy/Desktop/Texture/dome_normal_1001.jpg') bardejov = ImageTk.PhotoImage(bard) label1 = Label(self, image=bardejov) # 我们必须保留对图像的引用,以防止图像被垃圾收集。 label1.image = bardejov # 将标签放置在框架上的x = 20和y = 20坐标处。 label1.place(x=0, y=20) bard2 = Image.open( r'/Users/badboy/Desktop/Texture/dome_gloss_1001.jpg') img2 = ImageTk.PhotoImage(bard2) label2 = Label(self, image=img2) label2.image = img2 label2.place(x=800, y=20) bard3 = Image.open( r'/Users/badboy/Desktop/Texture/dome_normal_1001.jpg') img3 = ImageTk.PhotoImage(bard3) label3 = Label(self, image=img3) label3.image = img3 label3.place(x=20, y=520)
def initUI(self): self.master.title("Choisce of Mode") #Title self.pack(fill=BOTH, expand=1) Style().configure("TFrame", background="#CCC") # list of texts for labels above the dual choice question box textbase = ["Choose the Scene Mode", "Are you ready to rec?", "Do you need a preview?"] # list of texts on left and right button, respectively buttonbase = ['General','Violence', 'Cancel','Record', 'Preview', 'Record'] # files of images should be 80x80 named qNl.png and qNr.png # for left and right Nth question, respectively imLeft = ImageTk.PhotoImage(Image.open('q' +str(QFlag)+'l.png')) imRight = ImageTk.PhotoImage(Image.open('q' +str(QFlag)+'r.png')) lbl2 = Label(text=textbase[QFlag-1], width=100, background="#CCC", foreground="black", font=("Courier", 12)) Button1 = Button(self, text=buttonbase[QFlag*2-2], command= self.leftbut) Button2 = Button(self, text=buttonbase[QFlag*2-1], command= self.rightbut) # positionning of components label1 = Label(self, image=imLeft) label1.image = imLeft label1.place(x=21, y=27) label2 = Label(self, image=imRight) label2.image = imRight label2.place(x=147, y=28) Button1.place(x=25, y=117) Button2.place(x=151, y=117) lbl2.place(x=18, y=3)
def initUI(self): self.parent.title("Absolute positioning") self.pack(fill=BOTH, expand=True) style = Style() style.configure("TFrame", background="#333") size = 128, 128 ''' bard = Image.open("bardejov.jpg") bardThumbNail = bard.thumbnail(size, Image.BICUBIC) bardejov = ImageTk.PhotoImage(bard) label1 = Label(self , image=bardejov) label1.image = bardejov label1.place(x=20, y=20) ''' rot = Image.open("rotunda.jpg") rotunda = ImageTk.PhotoImage(rot) rot.thumbnail(size, Image.BICUBIC) label2 = Label(self, image=rotunda) label2.image = rotunda label2.place(x=40, y=160) minc = Image.open("mincol.jpg") mincol = ImageTk.PhotoImage(minc) minc.thumbnail(size, Image.BICUBIC) label3 = Label(self, image=mincol) label3.image = mincol label3.place(x=170, y=50)
def openfile(): filepath = filedialog.askopenfilename() chest = Image.open(filepath).resize((300, 300), Image.ANTIALIAS) chestjov = ImageTk.PhotoImage(chest) label1 = Label(self, image=chestjov) label1.image = chestjov label1.grid(row=1, column=0, padx=30, pady=7)
def insert_img(img2): global label1 img2 = img2.resize((300, 300), Image.ANTIALIAS) chestjov2 = ImageTk.PhotoImage(img2) label1 = Label(self, image=chestjov2) label1.image = chestjov2 label1.grid(row=1, column=0, padx=30, pady=7)
def make_dealer_card_show(self, card, showing=True): if (showing): card_image = Image.open(f'./images/{card}.png') else: card_image = Image.open(f'./images/purple_back.png') ci_width, ci_height = card_image.size card_image = ImageTk.PhotoImage( card_image.resize((ci_width // 10, ci_height // 10), Image.LANCZOS)) card_image_label = Label(image=card_image) card_image_label.image = card_image #card position by card number if (self.dealer_number_of_cards == 1): card_image_label.place(x=200, y=50) if (self.dealer_number_of_cards == 2): card_image_label.place(x=275, y=50) if (self.dealer_number_of_cards == 3): card_image_label.place(x=350, y=50) if (self.dealer_number_of_cards == 4): card_image_label.place(x=425, y=50) if (self.dealer_number_of_cards == 5): card_image_label.place(x=500, y=50) if (self.dealer_number_of_cards == 6): card_image_label.place(x=575, y=50) if (self.dealer_number_of_cards == 7): card_image_label.place(x=650, y=50) self.dealer_cards_images.append(card_image_label)
def _load_die_img(self): """Get random die img""" die_img = Image.open(self.die.get_random()) die = ImageTk.PhotoImage(die_img) lbl = Label(self, image=die) lbl.image = die lbl.place(x=20, y=20)
def create_image(self, frame, new=False): """ Method for initializing the main image and resizing it to fit the required size :param tkinter.ttk.Frame frame: Frame object used for current image :param bool new: Placeholder variable for swapping default image """ if new is False: orig_image = Image.open( os.path.join(os.getcwd(), "sample_output.jpg")) else: orig_image = Image.open(os.path.join(os.getcwd(), "idwout.jpg")) resize_image = orig_image.resize((1000, 600), Image.ANTIALIAS) idw_image_jov = ImageTk.PhotoImage(resize_image) idw_label = Label(frame, image=idw_image_jov) idw_label.image = idw_image_jov idw_label.grid(row=0, column=2, rowspan=8, padx=1, pady=30, sticky=W + S + N)
def initUI(self): self.master.title("Buttons") self.style = Style() self.style.theme_use("default") frame = Frame(self, relief=RAISED, borderwidth=1) frame.pack(fill=BOTH, expand=True) self.pack(fill=BOTH, expand=True) Quitbutton = Button(self, text="QUIT",command=quit) Quitbutton.pack(side=RIGHT) okButton = Button(self,text="ACTIVATE",command= self.BetaB) okButton.pack(side=LEFT) self.master.title("BETA B V1.0") self.pack(fill=BOTH, expand=1) Style().configure("TFrame", background="#000000") bard = Image.open("VA.png") bard = bard.resize((300, 260)) bardejov = ImageTk.PhotoImage(bard) label1 = Label(self, image=bardejov) label1.image = bardejov label1.place(x=0, y=0) label1.size()
def initUI(self): self.master.title("GPIO Tester") self.pack(fill=BOTH, expand=1) Style().configure("TFrame", background="#0F0F0F") img_analytics = Image.open("analytics.png") image1 = ImageTk.PhotoImage(img_analytics) label1 = Label(self, image=image1) label1.image = image1 label1.place(x=20, y=20) img_tools = Image.open("tools.png") image2 = ImageTk.PhotoImage(img_tools) label2 = Label(self, image=image2) label2.image = image2 label2.place(x=40, y=160)
def add_image_to_convert(img): """ this function is showing the image on the screen """ im = img.resize((600, 600), Image.ANTIALIAS) tkimage = ImageTk.PhotoImage(im) myvar = Label(root, image=tkimage) myvar.image = tkimage myvar.place(relx=.5, x=400, y=400, anchor="center")
def initUI(self): self.master.title('Image') tatras = ImageTk.PhotoImage(self.img) label = Label(self, image=tatras) label.image = tatras label.pack() self.pack()
def initUI(self): self.parent.title('Absolute positioning') self.pack(fill=BOTH, expand=1) self.style.configure('TFrame', background='grey') apple_png = PhotoImage(file='images/nibbles/apple.png') label1 = Label(self, image=apple_png) label1.image = apple_png label1.place(x=20, y=20) dot_png = PhotoImage(file='images/nibbles/dot.png') label2 = Label(self, image=dot_png) label2.image = dot_png label2.place(x=40, y=160) head_png = PhotoImage(file='images/nibbles/head.png') label3 = Label(self, image=head_png) label3.image = head_png label3.place(x=170, y=50)
def initUI(self): # TitleBar self.master.title("Easy Checkout") self.pack(fill=BOTH, expand=True) # Stretch self.columnconfigure(3, weight=1) self.columnconfigure(0, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) # Row0 : Labels for Sections cmd = Label(self, text="Commands") cmd.grid(sticky=W, pady=4, padx=5, row = 0, column = 0) pic = Label(self, text="Picture") pic.grid(sticky=W, pady=4, padx=5, row = 0, column = 1) items = Label(self, text="Items") items.grid(sticky=W, pady=4, padx=5, row = 0, column = 3) # ItemList itemList = Text(self) itemList.grid(row=1, column=3, rowspan=4, padx=5, sticky=E+W+S+N) #Buttons abtn = Button(self, text="Activate", command = lambda :pNUM(3)) abtn.grid(row=1, column=0) cbtn = Button(self, text="Close") cbtn.grid(row=2, column=0, pady=4) hbtn = Button(self, text="Help") hbtn.grid(row=5, column=0, padx=5) obtn = Button(self, text="OK") obtn.grid(row=5, column=3) #Pictures path = "result.jpg" pil_img = Image.open(path) #Pictures : Resize to Show w_box = 202 h_box = 360 w, h = pil_img.size resizedImg = resize(w, h, w_box, h_box, pil_img) img = ImageTk.PhotoImage(resizedImg) pannel = Label(self, image = img) pannel.image = img pannel.grid(row=1, column = 1, columnspan = 2, rowspan = 4, sticky = E+W+S+N, padx = 5)
def load_image(): global filename fm = askopenfilename(filetypes=[("Images", "*.png")], initialdir="../Data") image = Image.open(fm) image = image.resize((150, 150), Image.ANTIALIAS) image = ImageTk.PhotoImage(image) label1 = Label(image=image, anchor=CENTER, background='#193446', width=500) label1.image = image label1.pack(fill=X, side=TOP) filename = fm
def picture(self, adr): """ This function creates three lables with pictures, first label show differences between pictures in next two labels. Parameters: ---------- adr: str Path to chart. """ adress_1 = self.listOfPaths[adr] adress_2 = adress_1.replace(self.directory1, self.directory2) file_img1 = Image.open(adress_1) try: file_img2 = Image.open(adress_2) except FileNotFoundError: adr = self.listOfPaths[self.i] self.addToListbox(adr) self.onNoPlot() return None self.fill_text_fields(adress_1, adress_2) diff = ImageChops.difference(file_img1, file_img2) diff = diff.resize((600, 600)) diffjov = ImageTk.PhotoImage(diff) label1 = Label(self, image=diffjov) label1.image = diffjov label1.place(x=10, y=60) file_img1 = file_img1.resize((600, 600)) image_2 = ImageTk.PhotoImage(file_img1) label2 = Label(self, image=image_2) label2.image = image_2 label2.place(x=620, y=60) file_img2 = file_img2.resize((600, 600)) image_3 = ImageTk.PhotoImage(file_img2) label3 = Label(self, image=image_3) label3.image = image_3 label3.place(x=1230, y=60)
def display_picture(self, picture, picture_type): width = 500 width_percent = width / float(picture.size[0]) height = int((float(picture.size[0] * float(width_percent)))) resized_picture = picture.resize((width, height), Image.ANTIALIAS) resized_picture = ImageTk.PhotoImage(resized_picture) label = Label(self, image=resized_picture) label.image = resized_picture if picture_type == 'input': label.place(x=30, y=50) elif picture_type == 'output': label.place(x=560, y=50)
def initUI(self): self.master.title("Label") tatras = ImageTk.PhotoImage(self.img) label = Label(self, image=tatras) # reference must be stored label.image = tatras label.pack() self.pack()
def initialize_video_selection_ui(self): # Initialize logo picture logo = Label(self, image=self.logo_image) logo.image = self.logo_image logo.place(y=125, x=200, anchor=tk.CENTER) # Initialize settings button settings_button = Button(self, command=self.open_settings, image=self.settings_icon) settings_button.place(y=275, x=25, anchor=tk.CENTER) # Initialize select video button select_video_button = Button(self, text="Select Video") select_video_button.config(command=partial(self.select_video, [logo, select_video_button, settings_button], [select_video_button, settings_button])) select_video_button.place(y=200, x=200, anchor=tk.CENTER)
def initUI(self): self.master.title("Absolute positioning") self.pack(fill=BOTH, expand=1) Style().configure("TFrame", background="#333") bard = Image.open("bardejov.jpg") bardejov = ImageTk.PhotoImage(bard) label1 = Label(self, image=bardejov) label1.image = bardejov label1.place(x=20, y=20) rot = Image.open("rotunda.jpg") rotunda = ImageTk.PhotoImage(rot) label2 = Label(self, image=rotunda) label2.image = rotunda label2.place(x=40, y=160) minc = Image.open("mincol.jpg") mincol = ImageTk.PhotoImage(minc) label3 = Label(self, image=mincol) label3.image = mincol label3.place(x=170, y=50)
def initUI(self): Style().configure("TFrame", background="#333") # frame = dark gray background self.master.title("Absolute positioning") # set the title of the window # .master = gives access to the root window self.pack(fill=BOTH, expand=1) # pack() organizes widgets into horizontal # and vertical boxes. # Frame widget is accessed via the self attribute # to the Tk root window and expanded in both direction image1 = Image.open("plus.jpg") # create an image object image11 = ImageTk.PhotoImage(image1) # create a photo image object from an image label1 = Label(self, image=image11) # create a label with an image # labels can contain image / text label1.image = image11 # reference to the image to prevent # image being garbage collected label1.place(x=20, y=20) # place the label image2 = Image.open("identicon.jpg") image22 = ImageTk.PhotoImage(image2) label2 = Label(self, image=image22) label2.image = image22 label2.place(x=40, y=160) image3 = Image.open("facebook.jpg") image33 = ImageTk.PhotoImage(image3) label3 = Label(self, image=image33) label3.image = image33 label3.place(x=170, y=50)
def init_ui(self): self.style.configure("TFrame", background="#edeff4") image_kevin = Image.open( "images/kevin-mueller-6w-jK5Bfz2k-unsplash.jpg").resize((200, 200)) kevin = ImageTk.PhotoImage(image_kevin) label1 = Label(self, image=kevin) label1.image = kevin label1.place(x=20, y=20) image_craig = Image.open( "images/craig-melville-CY2sDlYLSuE-unsplash.jpg").resize( (200, 200)) craig = ImageTk.PhotoImage(image_craig) label2 = Label(self, image=craig) label2.image = craig label2.place(x=240, y=20) image_karl = Image.open( "images/karl-lee-gM7LYJYrBSw-unsplash.jpg").resize((200, 200)) karl = ImageTk.PhotoImage(image_karl) label2 = Label(self, image=karl) label2.image = karl label2.place(x=460, y=20)
def initUI(self): self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.rowconfigure(1, weight=1) self.rowconfigure(2, weight=1) self.rowconfigure(3, weight=1) def process(): global area global img area.delete(1.0, END) xray_process(img, add_text, insert_img) def insert_img(img2): global label1 img2 = img2.resize((300, 300), Image.ANTIALIAS) chestjov2 = ImageTk.PhotoImage(img2) label1 = Label(self, image=chestjov2) label1.image = chestjov2 label1.grid(row=1, column=0, padx=30, pady=7) def openfile(): global img global label1 filepath = filedialog.askopenfilename() img = Image.open(filepath).resize((300, 300), Image.ANTIALIAS) chest = Image.open(filepath).resize((300, 300), Image.ANTIALIAS) chestjov = ImageTk.PhotoImage(chest) label1 = Label(self, image=chestjov) label1.image = chestjov label1.grid(row=1, column=0, padx=30, pady=7) chest = Image.open("test.jpg").resize((300, 300), Image.ANTIALIAS) chestjov = ImageTk.PhotoImage(chest) label1 = Label(self, image=chestjov) label1.image = chestjov label1.grid(row=1, column=0, padx=30, pady=7) # The Browse button. abtn = Button(self, text="Browse", command=openfile) abtn.grid(row=2, column=0, pady=10) # The Process button, which begins the program. abtn = Button(self, text="Process", command=process) abtn.grid(row=3, column=0, pady=15) separator = ttk.Separator(self, orient=VERTICAL) separator.grid(column=1, row=0, rowspan=5, sticky='ns')
def select_image(self): global img_path img_path = filedialog.askopenfilename() image = Image.open(img_path) image = image.resize((600, 600), Image.ANTIALIAS) image = ImageTk.PhotoImage(image) panel = Label(self, image=image) panel.image = image panel.grid(row=1, column=0, columnspan=2, rowspan=4, padx=5, sticky=E + W + S + N)
def initUI(self, path, pic, xi, yi): stgImg = Image.open(str((path - 1) * 5) + "//" + str(pic) + ".jpg") # paths="/home/iamrishav/PycharmProjects/HelloWorld/0" stgImg = stgImg.resize((width, height), Image.ANTIALIAS) stgImg2 = ImageTk.PhotoImage(stgImg) # frame=Frame(master,height=800) # frame.pack(fill=X) data = pandas.read_csv("output" + str((path - 1) * 5) + ".csv", header=None) var = data.to_numpy() label = Label(self, image=stgImg2) label.image = stgImg2 label.place(x=543 * xi - 543 + 20, y=280 * yi - 300 + 10) #-269 label1 = Label(self) s = ttk.Style() s.theme_use('clam') s.configure("red.Horizontal.TProgressbar", foreground='red', background='red') progress = Progressbar(label1, style="red.Horizontal.TProgressbar", length=100, mode='determinate') progress['value'] = int(var[pic - 1][1] * 20) fn = str(var[pic - 1][1]) + " mins" fn1 = d[pic] #progress=Progressbar(label1,length=200,mode='determinate') #progress['value']=path*33 #fn=str(path*33) label2 = Label(self, text=fn, font="arial 12 bold", background="#f0d630") label2.place(x=543 * xi - 317 - 90, y=280 * yi - 50 + 17) label3 = Label(self, text=fn1, font="arial 12 bold", background="white") label3.place(x=543 * xi - 235.5 - 90, y=280 * yi - 50 + 18) progress.pack() label1.place(x=543 * xi - 540 + 20, y=280 * yi - 50 + 18) self.update_idletasks()
def show_images(self): self.open_images() if self.usable_images == []: print('No images opened') return num_rows = self.number_of_rows num_cols = self.number_of_columns # Arrange images for r in range(0, num_rows): for c in range(0, num_cols): current_image = self.usable_images[r * num_cols + c] label = Label(self.image_frame, image=current_image) label.image = current_image label.grid(row=r, column=c) self.image_labels.append(label)
def show_images(self): self.open_images() if self.usable_images == []: self.parent.print_to_console("No images opened") return num_rows = self.config.number_of_rows.get() num_cols = self.config.number_of_columns.get() # Arrange images for r in range(0, num_rows): for c in range(0, num_cols): current_image = self.usable_images[r * num_cols + c] label = Label(self.image_frame, image=current_image) label.image = current_image label.grid(row=r, column=c) self.image_labels.append(label)
def new_game_or_restore(self): #Add Spade cards image for load screen new_game_image = Image.open('./images/honors_spade-14.png') ngi_width, ngi_height = new_game_image.size new_game_image = ImageTk.PhotoImage( new_game_image.resize((ngi_width // 6, ngi_height // 6), Image.LANCZOS)) new_game_image_label = Label(image=new_game_image) new_game_image_label.image = new_game_image new_game_image_label.place(x=200, y=150) #Add new game button for load screen (red button) image = Image.open("./images/newgame.png") i_width, i_height = image.size image = ImageTk.PhotoImage( image.resize((int(i_width // 20), int(i_height // 20)), Image.LANCZOS)) new_game_but = tk.Button(highlightthickness=0, command=lambda: [self.init_game()]) new_game_but.config(activebackground='darkgreen', image=image, bg="darkgreen", bd=0) new_game_but.image = image new_game_but.place(x=200, y=400) #Add restore game button for load screen (green button) image = Image.open("./images/continue.png") i_width, i_height = image.size image = ImageTk.PhotoImage( image.resize((int(i_width // 3.25), int(i_height // 3.25)), Image.LANCZOS)) restore_game_but = tk.Button( highlightthickness=0, command=lambda: [restore(self), self.init_game()]) restore_game_but.config(activebackground='darkgreen', image=image, bg="darkgreen", bd=0) restore_game_but.image = image restore_game_but.place(x=435, y=400) #add all widgets to a list self.load_screen_contents.append(new_game_image_label) self.load_screen_contents.append(new_game_but) self.load_screen_contents.append(restore_game_but)
def display(self): root = Toplevel() root.wm_title(self.text) path = "New/" + self.imgPath pomoc = Image.open(path) basewidth = 600 wpercent = (basewidth / float(pomoc.size[0])) hsize = int((float(pomoc.size[1]) * float(wpercent))) pomoc = pomoc.resize((basewidth, hsize), Image.LANCZOS) img = ImageTk.PhotoImage(pomoc) panel = Label(root, image=img) panel.image = img panel.pack() root.mainloop()
def initUI(self): self.master.title("Recognition of a traffic situation in real-time") self.style = Style() self.style.theme_use("default") frame = Frame(self, relief=RAISED, borderwidth=3) frame.pack(fill=BOTH, expand=True) bard = Image.open("traffic.jpg") bardejov = ImageTk.PhotoImage(bard) label1 = Label(self, image=bardejov, borderwidth=3) label1.image = bardejov label1.place(x=0, y=0) self.pack(fill=BOTH, expand=True) closeButton = Button(self, text="Close", command=close_window) closeButton.pack(side=RIGHT, padx=5, pady=5) okButton = Button(self, text="Select file", command=Object_detect) okButton.pack(side=RIGHT)
def show_about(self): about = Toplevel(self.master) about.title('About {}'.format(self.version[:-5])) about.focus() about.resizable(0, 0) logo_lbl = Label(about, image=self.logo) logo_lbl.image = self.logo logo_lbl.grid(row=0, column=0, padx='7 11', pady=13, sticky='n') about_frame = Frame(about, padding='0 10 10 10') about_frame.grid(row=0, column=1) Label(about_frame, text=self.version).grid(sticky='w') Label(about_frame, text='Developer: Joel W. Dafoe').grid(pady='6', sticky='w') link = Link(about_frame, text='http://cyberdatx.com', foreground='blue', cursor='hand2') link.grid(sticky='w') link.bind('<Button-1>', lambda e: webbrowser.open('http://cyberdatx.com')) Label(about_frame, text=self.description, wraplength=292).grid(columnspan=2, pady=6, sticky='w') cls_btn = Button(about_frame, text='OK', command=about.destroy) cls_btn.grid(column=1, sticky='e') cls_btn.focus() about.bind('<Return>', lambda e: cls_btn.invoke())