我正在使用tkinter的“askokcancel”消息框警告用户弹出一个不可逆转的动作。
from tkinter import Tk
Tk().withdraw()
from tkinter.messagebox import askokcancel
askokcancel("Warning", "This will delete stuff")
我想将“确定”按钮(从“确定”)的文本更改为“删除”,以使其不那么温和。
这可能吗?
如果没有,实现它的另一种方法是什么?最好不引入任何依赖...
答案 0 :(得分:7)
为什么不打开子窗口,从而使用您自己的按钮创建自己的框,如下所示:
from tkinter import *
def messageWindow():
win = Toplevel()
win.title('warning')
message = "This will delete stuff"
Label(win, text=message).pack()
Button(win, text='Delete', command=win.destroy).pack()
root = Tk()
Button(root, text='Bring up Message', command=messageWindow).pack()
root.mainloop()
答案 1 :(得分:5)
不,无法更改内置对话框的按钮文本。
您最好的选择是创建自己的对话框。这不是很难做到,它让你可以绝对控制对话框小部件中的内容。
答案 2 :(得分:-1)
是正确的,您不能在tkinter消息框中更改名称,但是可以创建自己的消息框类,以便可以多次重用。以下代码与tkinter消息框相同,但是它具有args,kwargs作为argumesnts。这只是为了轻松。 我也在学习,所以代码没有闪烁和警报。我将编辑我的代码的人会感谢他/她。
# Welcome to Serverless!
#
.......
# Happy Coding!
plugins:
- serverless-offline
service: xxxxx
# app and org for use with dashboard.serverless.com
app: yyyyy
org: xxxx
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: nodejs12.x
region: us-east-1
# here we put the layers we want to use
layers:
# Google Chrome for AWS Lambda as a layer
# Make sure you use the latest version depending on the region
# https://github.com/shelfio/chrome-aws-lambda-layer
- arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10
# function parameters
# you can overwrite defaults here
# stage: dev
# region: us-east-1
.....
functions:
hello:
handler: handler.hello
# main:
# handler: handler.main
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
events:
- http:
path: hello/get
method: get
.....