Python | Tkinter中的文本区域和按钮

Library:

图书馆:

Tkinter

Tkinter (Tkinter)

Tkinter(Tk interface) is a Standard python library that is used to create easy, fast, and simple GUI applications.

Tkinter(Tk接口)是一个标准的python库,用于创建简单,快速和简单的GUI应用程序。

Download Tkinter:

下载Tkinter:

General Way:
pip install python-tk

Pycharm Users:
Go to the project interpreter and install tkinter from there.

In this tutorial, we will create a label and text area, and we will extract the text from the text area, and we will see the functioning of the buttons.

在本教程中,我们将创建一个标签和文本区域,并从文本区域中提取文本,然后我们将看到按钮的功能。

Tkinter功能 (Tkinter functions)

  1. Importing all the inner functions of the Tkinter: from tkinter import *

    导入Tkinter的所有内部功能 :从tkinter import *

  2. Creating Root: root=Tk(), this function will create the root window.

    创建Rootroot = Tk() ,此函数将创建根窗口。

  3. Setting Geometry: root.geometry("500x500") we can set the geometry.

    设置几何root.geometry(“ 500x500”)我们可以设置几何。

  4. Setting Title: root.title("<Set the title>") we can set the title with the help of this function

    设置标题root.title(“ <设置标题>”)我们可以借助此功能设置标题

  5. Creating Label: Label(root,text="Hello"), we can set the label with the help of this function.

    创建标签Label(root,text =“ Hello”) ,我们可以借助此功能设置标签。

  6. Creating Text areas: Input(root,textvariable=<set text variable>,width=<set width>)

    创建文本区域Input(root,textvariable = <设置文本变量>,width = <设置宽度>)

  7. Creating Buttons: Button(root,text="<Set text>",command=<set funnction>,bg=<set background color>)

    创建按钮按钮(root,text =“ <设置文本>”,command = <设置功能>,bg = <设置背景颜色>)

  8. Running Loop: root.mainloop(), without running this function we will not be able to open the window.

    运行循环root.mainloop() ,如果不运行此功能,我们将无法打开窗口。

Program:

程序:

# import the module and all specifications
from tkinter import *

# create the window and set geometry and title
root=Tk()
root.geometry("500x500")
root.title("Include Help")

# creating the commanding 
# function of the button
def get_value():
    name=Text_Area.get()
    # creating a new window
    root2=Tk()
    root2.geometry("500x500")
    root2.title("Include Help")
    # setting the Label in the window
    label2=Label(root2,text=f"Welcome To Include Help {name}")
    label2.place(x=160, y=80)
    root2.mainloop()

# set the string variable
Text_Area=StringVar()

# create a label
label=Label(root,text="Enter Your Name")

# placing the label at the right position
label.place(x=190,y=80)

# creating the text area
# we will set the text variable in this
Input=Entry(root,textvariable=Text_Area,width=30)
Input.place(x=130,y=100)

# create a button
button=Button(root,text="Submit",command=get_value,bg="green")
button.place(x=180,y=130)
root.mainloop()

Output:

输出:

Python | Text Area and Button in Tkinter (Output)

This is the output, so in the above code we have done like we will take the name with the help of text area and after pressing the button, the commands of function will work and we will pop the new window where our name will get displayed.

这是输出,因此在上面的代码中我们已经完成了工作,就像我们将在文本区域的帮助下获取名称一样,在按下按钮之后,函数的命令将起作用,并且我们将弹出一个显示名称的新窗口。

翻译自: https://www.includehelp.com/python/text-area-and-button-in-tkinter.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值