Многострочная проблема позиционирования текста в Tkinter - PullRequest
1 голос
/ 15 февраля 2020

Возникла проблема с моей программой tkinter на Python. В одиннадцатой строке я поместил \n, так как весь текст не соответствовал моему заданному размеру окна. Я хотел бы, чтобы новая строка начиналась справа (ie как нажатие клавиши ввода в редакторе текста). Появляется, когда вызывается новая строка, это основывает текст из центра. Я новичок в tkitner и поэтому не знаю всех команд / функций, поэтому помощь будет оценена. Iv'e добавил фото проблемы.


def password_basic_check():#Function that gets called when enter button is pressed. function check password matches. its lengh and if it has both upper and lower case letters
    if password_enter_txt.get() != password_reenter_txt.get():#checks if both passwords matches
        password_fault_report.configure(text='Passwords do not match, try again.')#prints this text out into the blank string

    elif len(password_reenter_txt.get()) < 8:#checks if password lengh is below 8 characters
        password_fault_report.configure(text='Password needs to be at least 8 characters long')

    elif password_reenter_txt.get().islower() == True or password_reenter_txt.get().isupper() == True:#if password returns true if string has lower and upper case letters are used
        password_fault_report.configure(text='Password needs have both upper\n and lower case lettes')

    else:
        password_fault_report.configure(text='Password correct')#if all of the password checks fail

window = Tk()
window.geometry('480x320') #setting size of window (pixles)
window.title('Password Checker')
window.iconbitmap('/Users/andypaling/Desktop/index.ico')#sets icon for window

welcome_lbl = Label(window, text='Welcome', font=('Arial', 26), fg='#71C2FE') #Label with text saying 'welcome' in light blue 
welcome_lbl.place(x=15, y=10) #placing welcome label in top left of window

under_line_lbl = Label(window, text='__________________', font=('Arial', 35), fg='#FFB56B') #orange line under blue for looks
under_line_lbl.place(x=0, y=40)

intro_lbl = Label(window, text='Please enter your password: ', font=('Arial', 14, 'bold italic'))#lable with text underlined and italics
intro_lbl.place(x=10, y=90)

password_enter_lbl = Label(window, text='Password: ', font=('Candara', 10))
password_enter_lbl.place(x=10, y=120)

password_enter_txt = Entry(window, width=20, relief='raised')#entry box for user to enter their password
password_enter_txt.place(x=10, y=135)

password_reenter_lbl = Label(window, text='Re-enter password', font=('Candara', 10))#same as above for password reenter lbl and entry
password_reenter_lbl.place(x=10, y=160)

password_reenter_txt = Entry(window, width=20, relief='raised')
password_reenter_txt.place(x=10, y=175)

password_fault_report = Label(window, text='', font=('Arial', 14))#Empty label to be filled later to report password errors 
password_fault_report.place(x=225, y=140)

password_enter_btn = Button(window, text='Enter.', relief='raised', width=6, bg='orange', command=password_basic_check)#button to enter password, when pressed, password_basic_check is called
password_enter_btn.place(x=10, y=210)


window.mainloop()

[photo of problem][1]


  [1]: https://i.stack.imgur.com/GdQ1Y.png

1 Ответ

0 голосов
/ 15 февраля 2020

Вы можете даже go для двух ярлыков, если у вас нет проблем здесь. Это самое простое решение

from tkinter import *


def password_basic_check():  # Function that gets called when enter button is pressed. function check password matches. its lengh and if it has both upper and lower case letters
    password_fault_report1.configure(text='')
    password_fault_report2.configure(text='')
    if password_enter_txt.get() != password_reenter_txt.get():  # checks if both passwords matches
        password_fault_report1.configure(
            text='Passwords do not match, try again.')  # prints this text out into the blank string

    elif len(password_reenter_txt.get()) < 8:  # checks if password lengh is below 8 characters
        password_fault_report1.configure(text='Password needs to be at least')
        password_fault_report2.configure(text='8 characters long')

    elif password_reenter_txt.get().islower() == True or password_reenter_txt.get().isupper() == True:  # if password returns true if string has lower and upper case letters are used
        password_fault_report1.configure(text='Password needs have both upper')
        password_fault_report2.configure(text='and lower case lettes')

    else:
        password_fault_report1.configure(text='Password correct')  # if all of the password checks fail


window = Tk()
window.geometry('480x320')  # setting size of window (pixles)
window.title('Password Checker')

welcome_lbl = Label(window, text='Welcome', font=('Arial', 26),
                    fg='#71C2FE')  # Label with text saying 'welcome' in light blue
welcome_lbl.place(x=15, y=10)  # placing welcome label in top left of window

under_line_lbl = Label(window, text='__________________', font=('Arial', 35),
                       fg='#FFB56B')  # orange line under blue for looks
under_line_lbl.place(x=0, y=40)

intro_lbl = Label(window, text='Please enter your password: ',
                  font=('Arial', 14, 'bold italic'))  # lable with text underlined and italics
intro_lbl.place(x=10, y=90)

password_enter_lbl = Label(window, text='Password: ', font=('Candara', 10))
password_enter_lbl.place(x=10, y=120)

password_enter_txt = Entry(window, width=20, relief='raised')  # entry box for user to enter their password
password_enter_txt.place(x=10, y=135)

password_reenter_lbl = Label(window, text='Re-enter password',
                             font=('Candara', 10))  # same as above for password reenter lbl and entry
password_reenter_lbl.place(x=10, y=160)

password_reenter_txt = Entry(window, width=20, relief='raised')
password_reenter_txt.place(x=10, y=175)

password_fault_report1 = Label(window, text='',
                               font=('Arial', 14))  # Empty label to be filled later to report password errors
password_fault_report1.place(x=150, y=140)
password_fault_report2 = Label(window, text='',
                               font=('Arial', 14))  # Empty label to be filled later to report password errors
password_fault_report2.place(x=150, y=170)


password_enter_btn = Button(window, text='Enter.', relief='raised', width=6, bg='orange',
                            command=password_basic_check)  # button to enter password, when pressed, password_basic_check is called
password_enter_btn.place(x=10, y=210)

window.mainloop()

Это может помочь:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...