I am totally new to Python and I am having some trouble figuring out how to open and display an image file from the file browser. I tried to use appJar and Tkinter. From Tkinter, I can select the image file, but the iamge will not be displayed. From appJar, I just have no clue on how to use the button to open the file browser. Here I attached the code, I wonder if anyone is able to help me. Thanks.
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
from tkinter.messagebox import showinfo
from tkinter.filedialog import askopenfile
def popup_bonus():
win = tk.Toplevel()
win.wm_title("Window")
a = ttk.Button(win, text="Open")
a.grid(row=0, column=0)
b = ttk.Button(win, text="Exit", command=win.destroy)
b.grid(row=1, column=0)
def popup_showinfo():
showinfo("About", "My Name, Python Version")
class Application(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
self.pack()
self.button_bonus = ttk.Button(self, text="File", command=popup_bonus)
self.button_bonus.pack()
self.button_showinfo = ttk.Button(self, text="Help", command=popup_showinfo)
self.button_showinfo.pack()
root = tk.Tk()
app = Application(root)
root.mainloop()
And this is the code using appJar
#import the library
from appJar import gui
import os
#create a GUI variable called app
app = gui('Window', '400x200')
app.setBg('silver')
#habdle button events
def press(button):
if button == 'About':
app.infoBox(title = 'About', message = 'Python Verison, Author')
if button == 'Exit':
app.stop()
if button == 'Open':
app.openBox(title=None, dirName=None, fileTypes=[('images', '*.png'), ('images', '*.jpg')], asFile=True, parent=None, multiple=False, mode='w')
# add & configure widgets - widgets get a name,to help referencing
app.setFont(size=18, family='Calibri', underline=False)
app.addLabel('title', 'File Select')
app.setLabelBg('title', 'grey')
app.setLabelFg('title','black')
# link the buttons to the function called press
fileMenu = ['Open','-','Exit']
helpMenu = ['About']
app.addMenuList('File', fileMenu, press)
app.addMenuList('Help', helpMenu, press)
# start the GUI
app.go()
Thanks again.