A couple of habitual tkinter utilities.
This situation assumes the following itemizing constructing
/itemizing/path lion.jpg tiger.jpg endure.gif some.txt
The next code will load lion, tiger, and endure as PhotoImages
which would possibly perchance well perchance be accessible as Photography.endure and Photography.flower. The
some.txt file is skipped over attributable to we produce now not load the itemizing
with “.txt”. Then this can even contrivance a menubutton that would possibly perchance preserve
between lion, tiger, and endure in step with photos. The worth of
the text variale animal would possibly be sure to this menubutton such
that changing this can even commerce the image on the button and
selecting a image will commerce the text variable.
from tkinter import Tk, Mark, StringVar from tk_oddbox import Photography, ImageLoader, ImageMenuButton tk = Tk() loader = ImageLoader(tk) loader.load_dir("/itemizing/path", "*.jpg") loader.load_dir("/itemizing/path", "*.gif") flower_label = Mark(image=Photography.flower) bear_label = Mark(image=Photography.endure) animal_var = StringVar animal_var.dilemma("lion") animal_choices = ["lion", "tiger", "bear"] animal_menu = ImageMenuButton(tk, animal_var, animal_choices) animal_menu.grid(row=0, column=0) tk.mainloop()
The expressions appreciate “*.gif” are glob expressions and are
handed to the Route.glob() technique within the pathlib module.
Discover the file for your platform. For of us that’re unsure which to take, learn more about installing applications.
We hate SPAM and promise to keep your email address safe