小编bal*_*iao的帖子

如何在 Python Tkinter 中仅关闭 TopLevel 窗口?

使用 Python Tkinter ,创建一个子面板(TopLevel)来显示内容并获取用户输入,用户输入后,单击“退出”,发现整个 GUI(主面板)也被破坏。如何只关闭顶层窗口?

from tkinter import *

lay=[]
root = Tk()
root.geometry('300x400+100+50')

def exit_btn():
    top = lay[0]
    top.quit()
    top.destroy()

def create():
    top = Toplevel()
    lay.append(top)

    top.title("Main Panel")
    top.geometry('500x500+100+450')
    msg = Message(top, text="Show on Sub-panel",width=100)
    msg.pack()

    btn = Button(top,text='EXIT',command=exit_btn)
    btn.pack()

Button(root, text="Click me,Create a sub-panel", command=create).pack()
mainloop()
Run Code Online (Sandbox Code Playgroud)

python user-interface tk-toolkit tkinter

6
推荐指数
2
解决办法
1万
查看次数

为什么使用此代码可以生成随机密码?

这里有一个用于生成密码的代码段,我有2个关于此的问题,请问你能分享一下如何理解?

  1. urandom(6),来自urandom的帮助说,返回适合加密使用的n个随机字节,也就是说,它会返回6个字节,它是6个ASCII吗?

  2. ord(c) ,获取上面的字节的十进制基数,为什么这里转移到十进制基数?

帮助urandom:

def urandom(n): # real signature unknown; restored from __doc__
    """
    urandom(n) -> str

    Return n random bytes suitable for cryptographic use.
    """
    return ""
Run Code Online (Sandbox Code Playgroud)

Python脚本:

from os import urandom
letters = "ABCDEFGHJKLMNPRSTUVWXYZ"
password = "".join(letters[ord(c) % len(letters)] for c in urandom(6))
Run Code Online (Sandbox Code Playgroud)

python random passwords cryptography

2
推荐指数
1
解决办法
89
查看次数

如何在 Tcl 脚本中获取时间戳字符串?

我不知道 TCL 程序语言但知道 python,我需要修改一个 tcl 脚本来获得一个时间戳字符串,如050209012020 ( %Y-%m-%d %H:%M:%S)

tcl

0
推荐指数
1
解决办法
832
查看次数