for循环中的文本框输入并在滚动框中打印文本

text box input in for loop and print text in scrollbox

抱歉,如果有人问过这个问题。我已经搜索了 2 天了,我找不到答案。 我对编码很陌生,所以可能这就是为什么我找不到我犯的错误的原因。

我希望用户能够像这样在文本框中输入 2 个姓名:

John
Peter

如果用户按下 Vul 脚本 按钮,我希望滚动框中的输出如下所示:

create user "JOHN" identified by "JOHN";
Grant CONNECT to "JOHN ";
Grant RLOCUSR to "JOHN ";
create user "PETER" identified by "PETER";
Grant CONNECT to "PETER";
Grant RLOCUSR to "PETER";

上面的代码应该作为滚动框中的文本输出。 但这并没有发生。

这里是完整代码:

# Tkinter import ( The graphic user interface )
    from tkinter import *
    from tkinter import scrolledtext


# scripttext ( creat user ect ) script plus name copy into scrollbox
def vulscript():
    vultext = textbox.get("1.0", "end-1c")
    for names in [vultext]:
        scripttext = "create user \"" + names.upper() + "\" identified by \"" + names.upper() + "\";" \
             "\n""Grant CONNECT to \"" + names.upper() + "\";" \
             "\n" "Grant RLOCUSR to \"" + names.upper() + "\";" "\n"
        scr.insert(0.0, scripttext)


# Clearbutton function
def clear():
    textbox.delete(1.0, END)
    scr.delete(1.0, END)


# Making the screen
root = Tk()
root.title("Webnaam toevoegen script")
root.geometry("710x500")
root.resizable(width=FALSE, height=FALSE)
root.configure(bg='#f0f5f5')

# Script vul button
vulbutton = Button(root, text="Vul script", bg='#d1e0e0', command=vulscript, width=7)
vulbutton.grid(row=0, column=0)
# Clear button
clearbutton = Button(root, text="Clear all", bg='#d1e0e0', width=7, command=clear)
clearbutton.grid(row=1, column=0, sticky=N)

# Name label and text box next to it
namelabel = Label(root, text="Name", bg='#f0f5f5')
namelabel.grid(row=0, column=1, sticky=N)
textbox = Text(root, width=18, height=29)
textbox.grid(row=1, column=1, sticky=N)

# script label
scriptlabel = Label(root, text="Script", bg='#f0f5f5')
scriptlabel.grid(row=0, column=2)

# Scroll tekst window
scrolW = 30
scrolH = 3
scr = scrolledtext.ScrolledText(root, width=60, height=29, wrap=WORD)
scr.grid(row=1, column=2)


root.mainloop()

我添加了一张图片并做了一些解释。

你要做的就是在有换行符的地方拆分你的 vultext:

def vulscript():
    vultext = textbox.get("1.0", "end-1c")
    vultext=vultext.split('\n')
    print(vultext)
    for names in vultext:
        scripttext = "create user \"" + names.upper() + "\" identified by \"" + names.upper() + "\";" \
             "\n""Grant CONNECT to \"" + names.upper() + "\";" \
             "\n" "Grant RLOCUSR to \"" + names.upper() + "\";" "\n"
        scr.insert(0.0, scripttext)