Tkinter从输入框中获取文本

2024-09-30 01:21:50 发布

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

我想知道如何从Tkinter输入框中获取文本。我用这个网站制作了用户界面:https://visualtk.com。但是现在我不知道如何获取输入的文本。我将脚本粘贴到这里:

import tkinter as tk
import tkinter.font as tkFont

class App:
    def __init__(self, root):
        #setting title
        root.title("Login")
        #setting window size
        width=497
        height=214
        screenwidth = root.winfo_screenwidth()
        screenheight = root.winfo_screenheight()
        alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        root.geometry(alignstr)
        root.resizable(width=False, height=False)

        GLabel_129=tk.Label(root)
        GLabel_129["bg"] = "#ff8c00"
        ft = tkFont.Font(family='Times',size=28)
        GLabel_129["font"] = ft
        GLabel_129["fg"] = "#ffffff"
        GLabel_129["justify"] = "left"
        GLabel_129["text"] = "Login:"
        GLabel_129.place(x=0,y=10,width=497,height=66)

        GLabel_333=tk.Label(root)
        GLabel_333["bg"] = "#1e9fff"
        ft = tkFont.Font(family='Times',size=10)
        GLabel_333["font"] = ft
        GLabel_333["fg"] = "#01aaed"
        GLabel_333["justify"] = "center"
        GLabel_333["text"] = ""
        GLabel_333.place(x=0,y=80,width=497,height=15)

        GLineEdit_552=tk.Entry(root)
        GLineEdit_552["borderwidth"] = "1px"
        ft = tkFont.Font(family='Times',size=14)
        GLineEdit_552["font"] = ft
        GLineEdit_552["fg"] = "#333333"
        GLineEdit_552["justify"] = "left"
        GLineEdit_552["text"] = ""
        GLineEdit_552.place(x=110,y=100,width=375,height=32)

        GLineEdit_314=tk.Entry(root)
        GLineEdit_314["borderwidth"] = "1px"
        ft = tkFont.Font(family='Times',size=14)
        GLineEdit_314["font"] = ft
        GLineEdit_314["fg"] = "#333333"
        GLineEdit_314["justify"] = "left"
        GLineEdit_314["text"] = ""
        GLineEdit_314.place(x=110,y=140,width=375,height=32)
        GLineEdit_314["show"] = "*"

        GLabel_702=tk.Label(root)
        ft = tkFont.Font(family='Times',size=14)
        GLabel_702["font"] = ft
        GLabel_702["fg"] = "#ff0000"
        GLabel_702["justify"] = "left"
        GLabel_702["text"] = "Username:"
        GLabel_702.place(x=10,y=100,width=100,height=32)

        GLabel_648=tk.Label(root)
        ft = tkFont.Font(family='Times',size=14)
        GLabel_648["font"] = ft
        GLabel_648["fg"] = "#ff0000"
        GLabel_648["justify"] = "left"
        GLabel_648["text"] = "Password:"
        GLabel_648.place(x=10,y=140,width=100,height=32)
if __name__ == "__main__":
    root = tk.Tk()
    app = App(root)
    root.mainloop()

是否有任何命令或函数来获取文本?或者我需要一个按钮来输入文本吗


Tags: sizerootwidthfamilytkfontheighttimes

热门问题