How to put text in input line: how to ask for user input on the command line while providing a 'default' answer that the user can edit or delete?

后端 未结 4 1528
忘了有多久
忘了有多久 2020-12-18 21:07

I am creating a Python script that asks for input from the command line. The user will have the ability to edit a part of a file. I can ask for the new information and overw

4条回答
  •  醉梦人生
    2020-12-18 21:35

    You could do it with tkinter:

    from tkinter import *
    def enter():
        global commandEntry
        command = commandEntry.get()
        # Do stuff with command
        commandEntry.delete(0, END)
    def edit_line(line):
        global commandEntry
        commandEntry.insert(0, line)
    root = Tk()
    messageVar = StringVar()
    messageVar.set("Enter a command:")
    message = Label(root, textvariable=messageVar)
    commandEntry = Entry(root)
    enterButton = Button(root, text="Enter", command=enter)
    root.mainloop()
    

提交回复
热议问题