将小数位数转换为整数

时间:2019-03-20 18:21:50

标签: python button integer scale

我目前正在自学tkinter,但距离还不太远。我需要使用scale选项来选择密码的长度,然后按一个按钮,它将生成一个随机密码。运行时,我收到一条错误消息,说我无法将小数位数转换为整数。有帮助吗?

from tkinter import *
import random

chars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", 
"C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", 
"R", "S", "T", "U", "V", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", 
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
password = ""


def press(num):
    global chars, password
    print(num)
    for i in range(num):
        chooseletter = random.randint(0, 67)
        letter = chars[chooseletter]
        password = password + letter
    Label2.configure(text=password)


gui = Tk()
gui.geometry("400x200")
gui.title("Password Generator")

Label1 = Label(gui)
labelfont = ("Arial", 20, "bold")
Label1.config(text="Password Generator")
Label1.config(font=labelfont)
Label1.pack()

length = Scale(gui, from_=1, to=40, orient=HORIZONTAL, sliderlength=15, 
length=150)
length.pack()

Label2 = Label(text="")


##  Button
button = Button(gui, text="Generate", fg="blue", command=press(length))
button.pack()
Label2.pack()

gui.mainloop()

0 个答案:

没有答案
相关问题