我如何在输入答案后将其导入文本

2024-04-26 06:56:56 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我有这张报名表,有一部分你必须输入你的名字,我想把名字的答案带到后面的页面

import tkinter as tk

root = tk.Tk()
root.geometry("150x50+680+350")

def FormSubmission():
    global button_start
    button_start.place_forget()
    l1.place_forget()
    root.attributes("-fullscreen", True)
    frame = tk.Frame(root)
    tk.Label(frame, text="First Name:").grid(row=0)
    name = entry1 = tk.Entry(frame) # I want the name written here to be taken from here to the welcome text.
    entry1.grid(row=0, column=1)
    tk.Label(frame, text="Last Name:").grid(row=1)
    e2 = tk.Entry(frame)
    e2.grid(row=1, column=1)
    tk.Label(frame, text="Email:").grid(row=2)
    e3 = tk.Entry(frame)
    e3.grid(row=2, column=1)
    tk.Label(frame, text="Date of Birth:").grid(row=3)
    e4 = tk.Entry(frame)
    e4.grid(row=3, column=1)
    frame.pack(anchor='center', expand=True)
    button_next = tk.Button(frame, text = "Next", height = 2, width = 7, command =lambda: MainPage(frame))
    button_next.grid(row=4, column=1)

def MainPage(frame):
    global FormSubmission
    frame.pack_forget()
    root.attributes("-fullscreen", True)
    l1.place(x = 500, y = 10)
    button_start.place_forget()

l1 = tk.Label(root, text="Welcome," , font=("Arial", 44)) #As you can see here in this line I want the entry 1 name here after welcome and the comma
button_start = tk.Button(root, text="Start", height=3, width=20, command = FormSubmission)
button_start.place(x = 0, y = 10)
button_exit = tk.Button(root, text="Exit", command=root.destroy)
button_exit.place(x=1506, y=0)

root.mainloop()

我想做的是把条目1的答案放在欢迎语中。我所说的线路上有一个指示器


1条回答
网友
1楼 · 发布于 2024-04-26 06:56:56

下面是一个如何从小部件入口1提供文本的示例

  1. 在函数FormSubmission()中:在定义按钮的位置,应传递要在标签中显示的文本

    button_next = tk.Button(frame, text = "Next", height = 2, width = 7, command =lambda: MainPage(frame, entry1.get())) 
    
  2. 在Function主页(框架):您应该将文本设置为标签:

     def MainPage(frame, entry1):
          global FormSubmission
          frame.pack_forget()
          root.attributes("-fullscreen", True)
          l1.place(x = 500, y = 10)
          button_start.place_forget()
          l1.config(text="Welcome," + entry1) #<   -
    

enter image description here

enter image description here

相关问题 更多 >