tkinter Button点击执行函数comman=lambda

这篇博客介绍了如何利用Python的Tkinter库创建GUI应用程序,并重点讲解了Button组件的用法。通过实例展示了如何设置按钮文本、绑定命令及参数传递,用于实现用户交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Button = tk.Button(window,text = '开始监控',comman=lambda :getWorkStastic(urlPack.get(),filePack.get()))
补充以下代码的self.e()函数:#!/usr/bin/python #coding:utf-8 from tkinter import * import time root = Tk() def cacl(input_str): if "x" in input_str: ret = input_str.split("x") return int(ret[0]) * int(ret[1]) def callback(n): print(n) def callback1(n): print(n) class App: def __init__(self, master): frame1 = Frame(master) frame1.pack() frame = Frame(master) frame.pack() Button(frame, text="1",command=lambda: callback(1) ).grid(row=0,column=0) Button(frame, text="2",command=lambda: callback(2) ).grid(row=0,column=1) Button(frame, text="3",command=lambda: callback(3) ).grid(row=0,column=2) Button(frame, text="4",command=lambda: callback(4) ).grid(row=1,column=0) Button(frame, text="5",command=lambda: callback(5) ).grid(row=1,column=1) Button(frame, text="6",command=lambda: callback(6) ).grid(row=1,column=2) Button(frame, text="7",command=lambda: callback(7) ).grid(row=2,column=0) Button(frame, text="8",command=lambda: callback(8) ).grid(row=2,column=1) Button(frame, text="9",command=lambda: callback(9) ).grid(row=2,column=2) Button(frame, text="0",command=lambda: callback(0) ).grid(row=3,column=0) Button(frame, text="+",command=lambda: callback1("+") ).grid(row=3,column=1) Button(frame, text="-",command=lambda: callback1("-") ).grid(row=3,column=2) Button(frame, text="*",command=lambda: callback1("*") ).grid(row=4,column=1) Button(frame, text="/",command=lambda: callback1("/") ).grid(row=4,column=2) Button(frame, text="=", command=self.say_hi).grid(row=4,column=0) w = Label(frame1,text="输入结果") w.pack() self.e = Entry(frame1) self.e.pack(padx=5) w1 = Label(frame1,text="计算结果") w1.pack() v = StringVar() e1 = Entry(frame1, textvariable=v) v.set("") self.v = v e1.pack() def say_hi(self): print("hi there, everyone!",self.e.get()) input_str = self.e.get() self.v.set(cacl(input_str)) app = App(root) root.mainloop()
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值