from tkinter import *
from tkinter.filedialog import *
from tkinter.simpledialog import*
def func_open() :
filename = askopenfilename (parent = window, files = ("GIF files", "*.gif"), ("all files", "*.*"))
photo = PhotoImage(file = filename)
pLabel.configure(image = photo)
pLabel.image = photo
def func_exit() :
window.quit()
window.destroy()
def func_zoom() :
value = askinteger ("Enlarge multiple", enter a multiple to enlarge (2-8), minvalue = 2, maxvalue = 6)
global photo
photo = photo.zoom(value,value) #zoom
def func_subsample() :
value = askinteger ("reduce multiple", enter a multiple to reduce (2-8), minvalue = 2, maxvalue = 6)
global photo
photo = photo.subsample(value,value) #reduce
window = Tk()
window.geometry("400x400") window.title<:/p>
photo = PhotoImage() pLabel = Label(window, image = photo)
pLabel.pack(expand=1, anchor = CENTER)
mainMenu = Menu(window)
window.config(menu = mainMenu)
fileMenu = Menu(mainMenu)
mainMenu.add_cascade(label = "file", menu = fileMenu)
fileMenu.add_command(label = "Open File", command = func_open)
fileMenu.add_separator()
fileMenu.add_command(label = "End Program", command = func_exit)
fileMenu = Menu(mainMenu) #Create a new parent menu
mainMenu.add_cascade(label="image effect", menu=filMenu) #TopMenuName
fileMenu.add_command(label="zoom", command=func_zoom) #create submenu
FileMenu.add_separator() #Generate lines between submenus
fileMenu.add_command(label = "reduce", command = func_subsample) #create submenu
window.mainloop()
Select a file, press the upper menu image effect, press Zoom or Zoom to display the message box, and then enter a number in the message box, but you can't zoom in or out after that Could you tell me which part is wrong?
python
The func_open() that opens the file also displays the photo Make a variable with global photo.
func_zoom() and func_subsample()
def func_zoom() :
value = askinteger ("Enlarge multiple", enter a multiple to enlarge (2-8), minvalue = 2, maxvalue = 8)
global photo
photo = photo.zoom(value,value) #zoom
pLabel.configure(image=photo)
pLabel.image=photo
def func_subsample() :
value = askinteger ("reduce multiple", enter a multiple to reduce (2-8), minvalue = 2, maxvalue = 8)
global photo
photo = photo.subsample(value,value) #reduce
pLabel.configure(image=photo)
pLabel.image=photo
You can add it like this. I don't think you can do it because you didn't draw the picture again after increasing the number of pictures.
© 2024 OneMinuteCode. All rights reserved.