类和tkinter的简单结合


import tkinter as tk
class yemian1:
    def showone(self):
        root1 = tk.Tk()
        root1.geometry('300x400')
        self.label = tk.Label(root1)
        self.one = tk.StringVar(root1)
        one1 = tk.Entry(root1, width=80, textvariable=self.one)
        button1 = tk.Button(root1, text="1,求一个数组所有数的和", command=self.cal1)  # 将按钮绑定到cal1方法
        button2 = tk.Button(root1, text=",2,", command=self.cal2)
        button3 = tk.Button(root1, text=",3,", command=self.cal3)
        button4 = tk.Button(root1, text=",4,", command=self.cal4)
        button5 = tk.Button(root1, text=",5,", command=self.cal5)
        button6= tk.Button(root1, text="6,", command=self.cal6)
        one1.pack()
        button1.pack()
        button2.pack()
        button3.pack()
        button4.pack()
        button5.pack()
        button6.pack()
        self.label.pack()
        root1.mainloop()  # 显示root1窗口
    def cal1(self):
        self.obj = getone(self.one.get(),self.label)
        self.obj.fun1()

    def cal2(self):
        self.obj = getone(self.one.get(),self.label)
        self.obj.fun2()
    def cal3(self):
        self.obj = getone(self.one.get(),self.label)
        self.obj.fun3()
    def cal4(self):
        self.obj = getone(self.one.get(),self.label)
        self.obj.fun4()
    def cal5(self):
        self.obj = getone(self.one.get(),self.label)
        self.obj.fun5()
    def cal6(self):
        self.obj = getone(self.one.get(),self.label)
        self.obj.fun6()
class getone:
    def __init__(self, a,label):
        self.a = a
        self.label=label
    def fun1(self):
        l=self.a.split()
        sum=0
        for i in l:
            sum+=int(i)
        self.label.config(text=str(sum))

root = tk.Tk()
root.title('python_exercise')
root['height'] = 300
root['width'] = 400
but1 = tk.Button(root, command=yemian1().showone, text='填一个')
but1.pack()
root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bhZ567

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值