3

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()

Gui 1

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()

GUI 2

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.

finefoot
  • 9,914
  • 7
  • 59
  • 102
adama
  • 537
  • 2
  • 10
  • 29
  • 2
    You probably get two different styles because you are importing both tk and ttk in a manner that isn't advisable. Please provide a [mcve] which includes the imports, and which accurately creates the first style shown in your question. – Bryan Oakley Aug 24 '19 at 15:55
  • yeah, that was exactly the problem. I removed the tkinter.ttk import and everything is working fine now, thank you! – adama Aug 24 '19 at 18:35

1 Answers1

0

Refering to @Bryan Oakley´s answer I removed the from tkinter.ttk import * and afterwards I got the design as shown in my second screenshot.

Just deleted this one line although here is the working snippet.

from tkinter.ttk import *
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()
adama
  • 537
  • 2
  • 10
  • 29