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

歡迎訪問 生活随笔!

生活随笔

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

python

python编写姓名年龄_python小工具 - alert弹框输出姓名年龄、求和

發布時間:2023/12/2 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编写姓名年龄_python小工具 - alert弹框输出姓名年龄、求和 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# 導入tkinter的所有的包里面所有的內容from tkinter import *import tkinter.messageboxasmessagebox

# 從Frame派生一個Application類,這是所有Widget的父容器classApplication(Frame):

def __init__(self,master=None):

Frame.__init__(self,master)

self.pack()

self.createWidgets()

def createWidgets(self):

# 模塊1,設定用戶輸入一個字符,alert彈框輸出hello+該字符

self.helloLabel= Label(self, text=‘模塊1:請輸入您的姓名及年齡,程序將會打印出來‘)

self.helloLabel.pack() # pack()方法把Widget加入到父容器中,并實現布局。

self.nameInput=Entry(self)

self.nameInput.pack()

self.ageInput=Entry(self)

self.ageInput.pack()

self.alertButton= Button(self,text=‘提交‘,command=self.hello)

self.alertButton.pack()

# 模塊2,設定用戶輸入一個數字,alert彈框計算該數字的倍數

self.helloLabel= Label(self, text=‘模塊2:輸入任意數字后將計算1到該數字之間的和‘)

self.helloLabel.pack() # pack()方法把Widget加入到父容器中,并實現布局。

self.numberInput=Entry(self)

self.numberInput.pack()

self.alertButton= Button(self,text=‘提交‘,command=self.sum)

self.alertButton.pack()

# 退出Button設定

self.quitButton= Button(self, text=‘退出‘, command=self.quit)

self.quitButton.pack()

def hello(self):

name= self.nameInput.get() or ‘world‘# 獲取用戶輸入的內容

age= self.ageInput.get() or 20messagebox.showinfo(‘個人信息‘,‘姓名:%s\n年齡:%s歲‘ %(name,age)) # 調用用戶輸入的內容并打印出來

def sum(self):

number= int(self.numberInput.get()) # 獲取用戶輸入的內容

sum= 0

for i inrange(number):

i+= 1sum+=i

messagebox.showinfo(‘求和結果‘,‘1到%s之間的和為%s‘ % (number,sum)) # 調用用戶輸入的(數字 * 2)后并打印出來

# 實例化

app=Application()

# 設置窗口標題:

app.master.title(‘Hello World‘)

# 主消息循環

app.mainloop()

總結

以上是生活随笔為你收集整理的python编写姓名年龄_python小工具 - alert弹框输出姓名年龄、求和的全部內容,希望文章能夠幫你解決所遇到的問題。

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