[Python] Tkinter scale widget labeling

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to Tkinter and try to make a little password generator. For the length of the password I want to implement a Scale widget. I have a weird problem with displaying the labeling of the widget, I do not understand why I get two different designs.

    So this is a snippet from my main program:

    root = Tk()
    root.geometry("460x100")
    root.resizable(0,0)
    root.title("Password Generator")

    pw_label = Label(root, text="Password").grid(row=0, column=0, pady=4, padx = 4)
    length_label = Label(root, text="Length").grid(row=2, column=0, pady=4, padx = 4)
    pw_input = Entry(root, width=50)
    length_input = Scale(root, from_=8, to=50, orient=HORIZONTAL, length= 300)
    length_input.set(30)
    pw_input.grid(row = 0, column = 1, pady=4, padx = 4)
    length_input.grid(row = 2, column = 1, pady=4, padx = 4)
    Button(root, text='Quit', command=root.quit).grid(row=3, column=2, sticky=W, pady=4)
    Button(root, text='Generate', command=rand_pw).grid(row=2, column=2, sticky=W, pady=4)
    Button(root, text='Copy', command=copy).grid(row=0, column=2, sticky=W, pady=4)

    root.mainloop()


    [​IMG]

    As you can see, I have a blue slider and I have no scale under the Scale.

    And here is another, minimal slider example:

    from tkinter import *

    root = Tk()
    root.geometry("500x100")
    length_label = Label(root, text="Length").grid(row=0, column=0, pady=4, padx = 4)
    w2 = Scale(root, from_=0, to=50, tickinterval= 50, orient=HORIZONTAL, length=400)
    w2.set(23)
    w2.grid(row=0, column=1)


    mainloop()


    [​IMG]

    Can someone explain to me why I get two different stylings there? Both programs are in the same project folder in PyCharm. Also I start both examples in the same environment.

    I think I just made a stupid mistake but I can not find it.

    Continue reading...

Compartilhe esta Página