【发布时间】:2022-06-29 07:00:19
【问题描述】:
我不知道如何在输入的地方以外打印计算器的答案。
我要插入的代码是:
Button(master, text=\"Submit\",width=23, height=3, command=lambda(?)).grid(row=5, column=0, columnspan=3)
? = 我想要定义的东西
我希望条目中的文本 self.e 打印在条目之外的消息框或标签中。
from tkinter import *
from tkinter import ttk
import tkinter as tk
root = tk.Tk()
class sweltres:
def clearall(self):
self.e.delete(0,END)
def clear1(self):
self.txt=self.e.get()[:-1]
self.e.delete(0,END)
self.e.insert(0,self.txt)
def action(self,argi):
self.e.insert(END,argi)
def __init__(self,master):
master.title(\'Calculator\')
master.geometry(\"100x50\")
self.e = ttk.Entry(master)
self.e.grid(row=0,column=0,columnspan=6,pady=3)
self.e.focus_set()
Button(master,text=\'AC\',width=5,height=3,
fg=\"black\", bg=\"blue\",
command=lambda:self.clearall()).grid(row=4, column=2)
Button(master,text=\'C\',width=5,height=3,
fg=\"red\",bg=\"blue\",
command=lambda:self.clear1()).grid(row=4, column=0)
Button(master,text=\"7\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(\'7\')).grid(row=1, column=0)
Button(master,text=\"8\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(8)).grid(row=1, column=1)
Button(master,text=\"9\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(9)).grid(row=1, column=2)
Button(master,text=\"4\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(4)).grid(row=2, column=0)
Button(master,text=\"5\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(5)).grid(row=2, column=1)
Button(master,text=\"6\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(6)).grid(row=2, column=2)
Button(master,text=\"1\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(1)).grid(row=3, column=0)
Button(master,text=\"2\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(2)).grid(row=3, column=1)
Button(master,text=\"3\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(3)).grid(row=3, column=2)
Button(master,text=\"0\",width=5,height=3,
fg=\"white\",bg=\"blue\",
command=lambda:self.action(0)).grid(row=4, column=1)
Button(master, text=\"Exit wtf\",width=23,height=3,
fg=\"white\",bg=\"red\", command=master.destroy).grid(row=6, column=0, columnspan=3)
sweltres(root)
root.mainloop()
-
我不确定你想要什么。你能定义一个你想要的函数吗?
-
就像如果我单击按钮 12345 然后单击提交按钮,则会弹出一个 msgbox 或文本,并说类似“您选择的数字是 12345”
标签: python python-3.x tkinter tkinter-entry tkinter-button