User input in dialog box

后端 未结 3 1634
栀梦
栀梦 2021-02-20 08:16

Is there any library available in python for the graphical user entry input. I know about tk but I believe it takes some line of codes to do that. I am looking for

3条回答
  •  时光说笑
    2021-02-20 08:24

    I think this is the shortest you'll get without anything external:


    To start:

    from tkinter import *
    root=Tk()
    

    Instead of a=input('enter something'):

    a=StringVar()
    Label(root, text='enter something').pack()
    Entry(root, textvariable=a).pack()
    Button(root, text='Ok', command=lambda:DoSomethingWithInput(a.get)).pack()
    

    With a function DoSomethingWithInput(a)


    Instead of print('some text'):

    Label(root, text='some text').pack()
    Button(root, text='Ok', command=DoSomething).pack()
    

    With DoSomething() as what you do next.

提交回复
热议问题