@Pyhon3x

Почему не запускается код на Python?

Вот сам код:
import os
from tkinter import *
from tkinter import messagebox

try:
    os.chdir("C:Program FilesTSPassword")
except:
    dir = messagebox.askyesno("Ошибка", "Отсутствует директория паролей! Создать?")
if dir == True:
    newpath = r'C:/Program Files/TSPassword'
    if not os.path.exists(newpath):
        os.makedirs(newpath)

def mas(event):
    def edit(event):
        my_file = open("MLP.txt", "a")
        my_file.write("Метка: " + met.get() + " Логин: " + log.get() + " Пароль: " + pas.get() + '\n')
        my_file.close()
    master = Toplevel(root)
    met = StringVar()
    log = StringVar()
    pas = StringVar()
    text_met = Label(master, text="Введи название пароля (метка должна быть уникальной!)")
    text_met.pack()
    ent_met = Entry(master, textvariable=met)
    ent_met.pack()
    text_log = Label(master, text="Введи логин")
    text_log.pack()
    ent_log = Entry(master, textvariable=log)
    ent_log.pack()
    text_pas = Label(master, text="Введи пароль")
    text_pas.pack()
    ent_pas = Entry(master, textvariable=pas)
    ent_pas.pack()
    but = Button(master, text="Создать!")
    but.bind("", edit)
    but.pack()

def search(event):
        def go(event):
            word = s.get()
            filename = 'MLP.txt'
            with open(filename) as f:
                test = print(word if word in f.read() else messagebox.showerror('Error', 'Извини, но я ничего не нашел \nВозможно ты не ввел имя метки…'))
                test = test.str().replace('', '')
                lookup = s.get()
            with open(filename) as myFile:
                for num, line in enumerate(myFile, 0):
                    if lookup in line:
                        num = num
            with open('MLP.txt') as f:
                for index, line in enumerate(f):
                    if index == num:
                        a = line
                        break
    f = open('MLP.txt')
    line = f.readlines()
    test = line[num]
    '''
    Это будет в следующем обновлении
    copy = messagebox.askyesno('Результат', test + "\nСкопировать?")
    if copy == True:
        pyperclip.copy(test)
        messagebox.showinfo('ОК!', 'Скопировал, пользуйся!')
    elif copy == False:
    messagebox.showinfo('…', 'Ну, ладно…')
    '''
    s = StringVar()
    search = Toplevel(root)
    text = Label(search, text="Введи метку")
    text.pack()
    ent = Entry(search, textvariable=s)
    ent.pack()
    but = Button(search, text="Искать")
    but.bind("", go)
    but.pack()

def settings(event):
    def BS(event):
        os.chdir(message.get())
        message = StringVar()
        help = Label(Set, text="Введи директорию, (Пример: C:" + '/' + "test)")
        help.pack()
        ent = Entry(Set, textvariable=message)
        ent.pack()
        but = Button(Set, text = "Изменить")
        but.bind("", S)
        but.pack()
Set = Toplevel(root)
but_set = Button(Set, text="Директория паролей")
but_set.place(relx=.5, rely=.1, anchor="c", height=30, width=130, bordermode=OUTSIDE)
but_set.bind("", BS)


root = Tk()
root.geometry("370x250")

text = Label(text="Добро пожаловать!")
text.place(relx=.4, rely=.1, anchor="c", height=30, width=130, bordermode=OUTSIDE)

but = Button(text="Настройки")
but.place(relx=.8, rely=.1, anchor="c", height=30, width=130, bordermode=OUTSIDE)
but.bind("", settings)

butmas = Button(root, text="Создать пароль")
butmas.place(relx=.5, rely=.5, anchor="c", height=30, width=130, bordermode=OUTSIDE)
butmas.bind("", mas)

but_s = Button(root, text="Поиск пароля")
but_s.bind("", search)
but_s.place(relx=.5, rely=.7, anchor="c", height=30, width=130, bordermode=OUTSIDE)

root.mainloop()


Вывод консоли:
f = open('MLP.txt')
IndentationError: unindent does not match any outer indentation level

Можете помочь?
Заранее спасибо?
  • Вопрос задан
  • 142 просмотра
Решения вопроса 1
@Andy_U
У вас скорее всего проблема с отступами в функции settings. После определения внутренней функции BS вы сдвинулись обратно на два уровня, а надо было на один.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы