简体   繁体   English

如何使用tkinter messagebox返回函数的结果

[英]How return result of a function with tkinter messagebox

I am trying to write code that will return either head or tails and show it in a separate window (message box). 我正在尝试编写将返回头部或尾部的代码并将其显示在单独的窗口(消息框)中。 How can I show the result of my function in a separate window (message box)? 如何在单独的窗口(消息框)中显示我的功能结果?

import tkinter
import numpy as np
from tkinter import messagebox

result = []

def hola():

    coin = np.random.randint(0,2)
    if coin == 0:
       result.append("heads")
    else:
       result.append("tails")
    messagebox.showinfo( "Lucky you !", result )

top = tkinter.Tk()
B = tkinter.Button(top, text ="flip da coin", command = hola)

B.pack()
top.mainloop()

I think you want to do something like this; 我想你想做这样的事情;

import tkinter
import numpy as np
from tkinter import messagebox

def hola():

    coin = np.random.randint(0,2)
    if coin == 0:
       result = "heads"
    else:
       result = "tails"
    messagebox.showinfo( "Lucky you !", result )

top = tkinter.Tk()
B = tkinter.Button(top, text ="flip da coin", command = hola)

B.pack()
top.mainloop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM