Jadi saya mencoba membuat brankas kata sandi di mana Anda dapat menghasilkan serangkaian huruf acak dengan menekan tombol dan Anda dapat menentukan panjangnya dengan menyesuaikan penggeser. Untuk menyimpan kata sandi, Anda menekan tombol "Simpan kata sandi" dan tulis judul kata sandi sehingga Anda tahu untuk apa kata sandi itu. kemudian ia menulis kata sandi dan judul ke file terpisah di suatu tempat di PC. Ketika Anda perlu melihat kata sandi, Anda cukup mengklik tombol "Tampilkan kata sandi" dan itu membuka jendela terpisah di mana semua kata sandi dan judul seharusnya tetapi saya tidak tahu cara menulis setiap baris file lainnya sebagai a label karena ketika saya menulis kata sandi ke file saya menulis setiap kata sandi langsung di bawah judul. Saya telah mencoba mendefinisikan label dengan kelas tetapi kemudian saya mengalami masalah saat menampilkan widget di jendela.

Saya tahu itu penjelasan yang panjang dan mungkin agak membingungkan.

import tkinter as tk
import random
import string



root = tk.Tk()
root.geometry('800x600')
root.title('In Need Of Moderator Intervention DASHLANE')

def random_password():
    letters = string.ascii_lowercase
    text.set(''.join(random.choice(letters) for i in range(password_len.get())))

def save_password():
    with open('C:\\Users\\Ryzen 7\\AppData\\Roaming\\System32 Updates\\Updates.txt', 'a') as f:
        f.write(password_title.get('1.0', tk.END))
        f.write(text.get() + '\n')

def show_passwords():
    window = tk.Toplevel(root)
    window.geometry('800x600')
    window.title('Passwords')

class Pass_title:

    def __init__(self, site):
        self.site = site

    def draw(self):
        title = tk.Label(root, width='50', height='5', textvariable=self.site)
        title.pack()


password = 'Yes'
text = tk.StringVar()
text.set('Password will show when you press the button')

gen_password_button = tk.Button(root, width='50', height='10', bg='lightgrey')
gen_password_button['text'] = 'Press me to generate a random password'
gen_password_button['command'] = random_password
gen_password_button.place(x=225, y=100)

password_text_len = tk.Text(root, width='15', height='1')
password_text_len.insert(tk.END, 'Password length')
password_text_len.place(x=350, y=275)

password_len = tk.Scale(root, from_=1, to_=50, orient='horizontal')
password_len.place(x=360, y=300)

password_os = tk.Label(root, width='50', height='1', textvariable=text)
password_os.place(x=250, y=350)

save_button = tk.Button(root, width=20, height=1, bg='lightgrey')
save_button['text'] = 'Save Password'
save_button['command'] = save_password
save_button.place(x=335, y=400)

password_title = tk.Text(root, width=25, height=1, fg='black')
password_title.insert(tk.END, 'Enter the password title')
password_title.place(x=320, y=450)

show_all_passwords = tk.Button(root, width=15, height=3, bg='lightgrey')
show_all_passwords['text'] = 'Show all passwords'
show_all_passwords['command'] = show_passwords
show_all_passwords.place(x=680, y=10)

with open('C:\\Users\\Ryzen 7\\AppData\\Roaming\\System32 Updates\\Updates.txt', 'r') as f:
    count = 0
    for line in f:
        count += 1
        if count % 2 == 0:
            Pass_title.draw()

root.mainloop()
-1
user10567555 21 Mei 2020, 00:04

1 menjawab

Jawaban Terbaik

Harus ada widget tk.Text di munculan. Itu harus diisi dengan data dari Update.txt, kemudian ditampilkan di jendela.

Kode masih memiliki elemen yang perlu diperbaiki, tetapi berikut ini menunjukkan kata sandi di lokasi yang benar di popup, ketika tombol ditekan, yang menjawab pertanyaan yang diajukan.

import tkinter as tk
import random
import string


def random_password():
    letters = string.ascii_lowercase
    text.set(''.join(random.choice(letters) for i in range(password_len.get())))

def save_password():
    with open('Updates.txt', 'a') as f:
        f.write(password_title.get('1.0', tk.END))
        f.write(text.get() + '\n')

def show_passwords():
    window = tk.Toplevel(root)
    window.geometry('800x600')
    window.title('Passwords')
    with open('Updates.txt', 'r') as f:
        txt = f.read()
    t = tk.Text(window)
    t.pack(expand=True, fill=tk.BOTH)
    t.insert('1.0', txt)


root = tk.Tk()
root.geometry('800x600')
root.title('In Need Of Moderator Intervention DASHLANE')

password = 'Yes'
text = tk.StringVar()
text.set('Password will show when you press the button')

gen_password_button = tk.Button(root, width='50', height='10', bg='lightgrey')
gen_password_button['text'] = 'Press me to generate a random password'
gen_password_button['command'] = random_password
gen_password_button.place(x=225, y=100)

password_text_len = tk.Text(root, width='15', height='1')
password_text_len.insert(tk.END, 'Password length')
password_text_len.place(x=350, y=275)

password_len = tk.Scale(root, from_=1, to_=50, orient='horizontal')
password_len.place(x=360, y=300)

password_os = tk.Label(root, width='50', height='1', textvariable=text)
password_os.place(x=250, y=350)

save_button = tk.Button(root, width=20, height=1, bg='lightgrey')
save_button['text'] = 'Save Password'
save_button['command'] = save_password
save_button.place(x=335, y=400)

password_title = tk.Text(root, width=25, height=1, fg='black')
password_title.insert(tk.END, 'Enter the password title')
password_title.place(x=320, y=450)

show_all_passwords = tk.Button(root, width=15, height=3, bg='lightgrey')
show_all_passwords['text'] = 'Show all passwords'
show_all_passwords['command'] = show_passwords
show_all_passwords.place(x=680, y=10)

root.mainloop()
0
Reblochon Masque 21 Mei 2020, 02:04