我正在尝试编写返回头尾的代码,并将其显示在单独的窗口(消息框)中。如何在单独的窗口(消息框)中显示函数的结果?
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()
答案 0 :(得分:0)
我认为您想做这样的事情;
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()