【发布时间】:2017-12-25 04:32:55
【问题描述】:
#this picks a random number
def roll_dice():
from random import randint
for x in range(2):
print(randint(1,6))
#this makes the GUI
from tkinter import *
root = Tk()
root.title('first GUI')
root.geometry('500x500')
app = Frame(root)
app.grid()
label = Label(app, text = 'Dice Simulator')
label.grid()
button1 = Button(app, text = 'Roll Dice', command = roll_dice)
button1.grid()
root.mainloop()
我用它来模拟掷两个骰子并显示结果。这是我作为程序员的第一个项目,也是我制作 tkinter 的第一次体验
【问题讨论】:
-
您好,欢迎来到 Stack Overflow,请花点时间通过 welcome tour 了解您在此处的方式(并获得您的第一个徽章),阅读如何创建 Minimal, Complete, and Verifiable example并检查How to Ask Good Questions,这样您就有机会获得反馈和有用的答案。
-
为什么不添加另一个
Label或类似的并在那里写下你的结果?
标签: python python-3.x tkinter