日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2025/3/11 python 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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-tkPycharm 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)

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

    導入Tkinter的所有內部功能 :從tkinter import *

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

    創建Root : root = Tk() ,此函數將創建根窗口。

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

    設置幾何 : root.geometry(“ 500x500”)我們可以設置幾何。

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

    設置標題 : root.title(“ <設置標題>”)我們可以借助此功能設置標題

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

    創建標簽 : Label(root,text =“ Hello”) ,我們可以借助此功能設置標簽。

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

    創建文本區域 : Input(root,textvariable = <設置文本變量>,width = <設置寬度>)

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

    創建按鈕 : 按鈕(root,text =“ <設置文本>”,command = <設置功能>,bg = <設置背景顏色>)

  • 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 windowroot2=Tk()root2.geometry("500x500")root2.title("Include Help")# setting the Label in the windowlabel2=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:

    輸出:

    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

    總結

    以上是生活随笔為你收集整理的Python | Tkinter中的文本区域和按钮的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。