python按钮事件传入参数_关于Python Tkinter Button控件command传参问题的解决方式

  • Post author:
  • Post category:python


环境:Ubuntu14、Python3.4、Pycharm2018

一、使用command=lambda: 的形式传参

代码如下

from tkinter import *

import tkinter.messagebox as messagebox

def createpage(master):

master = Frame(root)

master.pack()

Label(master, text=’num1′).grid(row=0, column=0, stick=W, pady=10)

e1 = Entry(master)

e1.grid(row=0, column=1, stick=E)

Label(master, text=’num2′).grid(row=1, column=0, stick=W, pady=10)

e2 = Entry(master)

e2.grid(row=1, column=1, stick=E)

# Button传递参数

Button(

master, text=’加’, command=lambda: btn_def(e1.get(), e2.get())

).grid(row=2, column=0, stick=W)

Button(master, text=’减’).grid(row=2, column=1, stick=E)

Label(master, text=’说明’).grid