首页 > 解决方案 > 之后如何将此条目答案导入文本

问题描述

好的,所以我有这个注册表单,有一部分你必须输入你的名字,我希望那个名字的答案被带到后面的页面。

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 的答案并将其放入欢迎文本中。我所说的线上有一个指标。

标签: pythonuser-interfacetkinter

解决方案


这是一个如何从您的小部件条目中提供文本的示例1

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

    button_next = tk.Button(frame, text = "Next", height = 2, width = 7, command =lambda: MainPage(frame, entry1.get())) 
    
  2. 在函数 MainPage(frame): 你应该为你的标签设置文本:

     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) #<-------
    

在此处输入图像描述

在此处输入图像描述


推荐阅读