Connect with us

ViralNewsDude.com

tk-oddbox 0.0.1


Viral News

tk-oddbox 0.0.1

Project description A few odd tkinter utilities. Basic Description Images class–supports PhotoImages organized by file stem names they were loaded from. ImageMenuButton–uses images so loaded to make an image based menubutton/menu with an associated StringVar control variable. The user can select an image and its name will be set in the StringVar and displayed on…

tk-oddbox 0.0.1

Project description

A couple of habitual tkinter utilities.

Traditional Description

  • Photography class–helps PhotoImages organized by file stem names they were loaded from.
  • ImageMenuButton–makes spend of photos so loaded to develop a image essentially essentially based menubutton/menu
    with an connected StringVar wait on an eye on variable. The actual person can preserve a image and
    its title would possibly be dilemma within the StringVar and displayed on the button. If the StringVar
    is dilemma, the image displayed on button will commerce robotically–but it with out a doubt can even light repeatedly
    be a title of a image in Photography.

CAVEATS

  1. The kit is likely too explicit in focus to be worthwhile to many.
  2. Backwards compatibility is now not expected to be maintained.
  3. This code is perchance by no manner going to be manufacturing grade and in actual fact slight repairs is anticipated.

Example Utilization of Photography class

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.

Caveats:
  • Recordsdata are keyed by their stem title, so care needs to be
    feeble to retain some distance from title collisions.
  • File stem names beginning with underscores or that are now not
    exact python identifiers needs to be shunned.
  • StringVar wait on an eye on variable connected to an ImageMenuButton
    can even light by no manner be dilemma to one thing various than a title in Photography.
    This means an Entry widget with this StringVar is perchance a
    atrocious knowing.

Discover recordsdata

Discover the file for your platform. For of us that’re unsure which to take, learn more about installing applications.

Subscribe to the newsletter news

We hate SPAM and promise to keep your email address safe

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s Hot

To Top