Home>

The purpose is to have the password entered, and if it matches a predetermined password (eg 13579), proceed to the next process with IF syntax, and if it is wrong, end with else.
(I want to open the text input box in Python3 and get the input characters)

There was a sample of Tkinter so I tried it.

UserX Email Password BoX opens when you run the following:

①How can I get each input string?
② Even if you enter something in the dummy and press OK, you cannot proceed (Process finished with exit code 0)

First of all, it would be helpful if you could tell me how to display each input value with print (????) and if you press OK and the box disappears and proceed to the next process.

If I want to use other libraries
Please let me know if there is anything that can be done easily.

Thank you.

from tkinter import *
from tkinter import ttk
if __name__ == '__main__':
    root = Tk ()
    root.title ('Entry Test')
    root.resizable (False, False)
    frame1 = ttk.Frame (root, padding = 10)
    frame1.grid ()
    label1 = ttk.Label (frame1, text = 'Username', padding = (5, 2))
    label1.grid (row = 0, column = 0, sticky = E)
    label2 = ttk.Label (frame1, text = 'Email', padding = (5, 2))
    label2.grid (row = 1, column = 0, sticky = E)
    label3 = ttk.Label (frame1, text = 'Password', padding = (5, 2))
    label3.grid (row = 2, column = 0, sticky = E)
    # Username Entry
    username = StringVar ()
    username_entry = ttk.Entry (
        frame1,
        textvariable = username,
        width = 30)
    username_entry.grid (row = 0, column = 1)
    # Email Entry
    email = StringVar ()
    email_entry = ttk.Entry (
        frame1,
        textvariable = email,
        width = 30)
    email_entry.grid (row = 1, column = 1)
    # Password Entry
    password = StringVar ()
    password_entry = ttk.Entry (
        frame1,
        textvariable = password,
        width = 30,
        show = '*')
    password_entry.grid (row = 2, column = 1)
    frame2 = ttk.Frame (frame1, padding = (0, 5))
    frame2.grid (row = 3, column = 1, sticky = W)
    button1 = ttk.Button (frame2, text = 'OK')
    button1.pack (side = LEFT)
    button2 = ttk.Button (frame2, text = 'Cancel', command = quit)
    button2.pack (side = LEFT)
    root.mainloop ()
    print (password)
  • Answer # 1

    Q1, How can I get each input string?

    A1,username.get ()If you want to display it, please doprint (username.get ()).

    Reference: Associate widget variables

    Q2, I can't proceed even if I enter something in the dummy and press OK

      

    button2 = ttk.Button (frame2, text ='Cancel&apos ;, command = quit)

    Should I set the argumentcommandin the same way as

    ?

    button1 = ttk.Button (frame2, text = 'OK', command = quit)

      

    If it matches with a predetermined password (eg 13579), I want to proceed to the next process with IF syntax, and if it is wrong, I want to exit with else.

    I didn't understand the next process.
    Sample code that reflects what you want to do and your answers, for your reference.

    #-*-coding: utf-8-*-
    from tkinter import *
    from tkinter import ttk
    root = Tk ()
    root.title ('Entry Test')
    # Available after calling Tk (), declared at this position for reference from click events
    username = StringVar ()
    email = StringVar ()
    password = StringVar ()
    # Event when the OK button is clicked
    def ok_click ():
        if not (password.get () == "13579"):
            # Exit the screen = resume execution from the next line of root.mainloop ()
            root.quit ()
            return
        # If it matches
        print ("Done")
    def main ():
        root.resizable (False, False)
        frame1 = ttk.Frame (root, padding = 10)
        frame1.grid ()
        label1 = ttk.Label (frame1, text = 'Username', padding = (5, 2))
        label1.grid (row = 0, column = 0, sticky = E)
        label2 = ttk.Label (frame1, text = 'Email', padding = (5, 2))
        label2.grid (row = 1, column = 0, sticky = E)
        label3 = ttk.Label (frame1, text = 'Password', padding = (5, 2))
        label3.grid (row = 2, column = 0, sticky = E)
        # Username Entry
        username_entry = ttk.Entry (
            frame1,
            textvariable = username,
            width = 30)
        username_entry.grid (row = 0, column = 1)
        # Email Entry
        email_entry = ttk.Entry (
            frame1,
            textvariable = email,
            width = 30)
        email_entry.grid (row = 1, column = 1)
        # Password Entry
        password_entry = ttk.Entry (
            frame1,
            textvariable = password,
            width = 30,
            show = '*')
        password_entry.grid (row = 2, column = 1)
        frame2 = ttk.Frame (frame1, padding = (0, 5))
        frame2.grid (row = 3, column = 1, sticky = W)
        button1 = ttk.Button (frame2, text = 'OK', command = ok_click)
        button1.pack (side = LEFT)
        button2 = ttk.Button (frame2, text = 'Cancel', command = quit)
        button2.pack (side = LEFT)
        root.mainloop ()
        print (password.get ())
    if __name__ == '__main__':
        main ()

      

    In other libraries

    If you are limited to thePythonlanguage,PyQTorKivycan useQtDesigner.
    I have also told other questioners,
    GUI application creation in Python is not recommended for beginners exceptthose who love investigating.

    Japanese official document information is devastating.
    Sample code that does not work even if it exists.
    Inevitably, you need to hit secondary information (a system in which a beginner wrote an article on Qiita after seeing someone's sample) or English primary information.

    Contents for people who have written GUI applications in other languages.
    As prerequisite knowledge
    ・ Event driven programming
    ・ Layout manager (pack, grid, place if tkinter)
    Need to understand these two words.

    The recommended way is to create a WPF application in the C # language.
    I'm worried about a lot of sample code in Japanese.