# Tkinter Intvar

Tkinter 包含各种内置程序，它们的行为类似于标准 Python 数据类型，具有用于非常有效地欺骗 Tkinter 的组件（如标签和条目组件）的附加功能，使其与 Python 数据类型不同。

## 在 Tkinter 中使用 `IntVar()` 创建一个整数变量

``````from tkinter import *
``````

``````first_intvar=IntVar()
``````

``````def showDatatype():
second_label.config(text=f'{first_intvar.get()}{type(first_intvar.get())}')
``````

``````from tkinter import *
# Create GUI window object of TK
GUI_WINDOW=Tk()
GUI_WINDOW.title("Deltstack")
GUI_WINDOW.geometry("400x300")
def showDatatype():
second_label.config(text=f'{first_intvar.get()}{type(first_intvar.get())}')
# Create integer object using IntVar class
first_intvar=IntVar()
first_label=Label(GUI_WINDOW,text="Enter a first number",font=("bold 14"))
first_label.pack()
first_entry=Entry(GUI_WINDOW,textvariable=first_intvar)
second_label=Label(GUI_WINDOW,text="")
total_btn=Button(GUI_WINDOW,text="Total",command=showDatatype)
GUI_WINDOW.mainloop()
`````` ## 在 Tkinter 中使用 `IntVar()` 计算两个数字的和

``````first_intvar=IntVar()
second_intvar=IntVar()
``````

``````answer=Label(GUI_WINDOW,text="",font=("itelic 13"))
``````

``````def sumTwoNumbers():
try:
# Try to getting integer values and sum two numbers
total=first_intvar.get()+second_intvar.get()
answer.config(text=f"The sum of two numbers is {total}")
except Exception:
``````

``````from tkinter import *
# Create GUI window object of TK
GUI_WINDOW=Tk()
GUI_WINDOW.title("Deltstack")
GUI_WINDOW.geometry("400x300")
def sumTwoNumbers():
try:
# Try to getting integer values and sum two numbers
total=first_intvar.get()+second_intvar.get()
answer.config(text=f"The sum of two numbers is {total}")
except Exception:
# Create integer object using IntVar class
first_intvar=IntVar()
second_intvar=IntVar()
first_label=Label(GUI_WINDOW,text="Enter a first number",font=("bold 16"))
first_label.pack()
first_entry=Entry(GUI_WINDOW,textvariable=first_intvar)
second_label=Label(GUI_WINDOW,text="      Enter a second number",font=("bold 16"))
{"ft_lang_label":"__label__zh","ft_lang_prob":0.58227235,"math_prob":0.9483599,"size":3207,"snap":"2023-14-2023-23","text_gpt3_token_len":1234,"char_repetition_ratio":0.17265064,"word_repetition_ratio":0.30522087,"special_character_ratio":0.22606798,"punctuation_ratio":0.12337662,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9963706,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-07T04:55:34Z\",\"WARC-Record-ID\":\"<urn:uuid:c2709b56-6dda-411a-9428-b27f413b018c>\",\"Content-Length\":\"95300\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8eeb66ad-e8c2-4f84-aa65-27c1bd89abf1>\",\"WARC-Concurrent-To\":\"<urn:uuid:aac4b0cd-ca25-4e28-a0be-90b3bb3fd449>\",\"WARC-IP-Address\":\"47.246.23.78\",\"WARC-Target-URI\":\"https://www.zadmei.com/tkinter-intvar.html\",\"WARC-Payload-Digest\":\"sha1:GGE3JACYQJJHEPGIFUMWWYQZMMQCYDFI\",\"WARC-Block-Digest\":\"sha1:PMCC534NJYSRKBILRZUOPYUMLAV2FDXX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224653608.76_warc_CC-MAIN-20230607042751-20230607072751-00056.warc.gz\"}"}