1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import tkinter as tk
from tkinter import messagebox
import random

win = tk.Tk()
win.title('随机整数生成器')
winWidth = 550
winHeight = 330
t0 = tk.Label(win, text='下方输入最小值和最大值', font="微软雅黑 15", width=25, height=2)
t0.grid(row=0, column=1)
t1 = tk.Label(win, text='最小值:', font="微软雅黑 15", width=10, height=2, )
t1.grid(row=1, column=0)
e1 = tk.Entry(win, font="微软雅黑 15", width=20, justify='center')
e1.grid(row=1, column=1)
t2 = tk.Label(win, text='最大值:', font="微软雅黑 15", width=10, height=2)
t2.grid(row=2, column=0)
e2 = tk.Entry(win, font="微软雅黑 15", width=20, justify='center')
e2.grid(row=2, column=1)
t3 = tk.Label(win, text='随机值:', font="微软雅黑 15", width=20, height=2)
t3.grid(row=3, column=0)
t4 = tk.Label(win, font="微软雅黑 15", width=20, bg="white")
t4.grid(row=3, column=1)
t5 = tk.Label(win, text='Made by Macin', font="微软雅黑 10", width=25, height=2)
t5.grid(row=0, column=0)
t6 = tk.Label(win, font="微软雅黑 15", width=20, bg="white")
t7 = tk.Label(win, font="微软雅黑 15", width=20, bg="white")
var = tk.StringVar()

# 获取屏幕分辨率
screenWidth = win.winfo_screenwidth()
screenHeight = win.winfo_screenheight()

x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)

# 设置窗口初始位置在屏幕居中
win.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 禁止拉伸窗口大小
win.resizable(False, False)

win.iconbitmap('6.ico')

# win.wm_attributes("-alpha", 1) # 透明度(0.0~1.0)


def num():
x = e1.get()
y = e2.get()
t6["text"] = str(str.isdigit(x))
t7["text"] = str(str.isdigit(y))
if t6["text"] == "True" and t7["text"] == "True":
pass
else:
messagebox.showinfo('提示', '我只认识正整数')
e1.delete(0, "end")
e1.insert(0, "")
e2.delete(0, "end")
e2.insert(0, "")

def ran():
x = e1.get()
y = e2.get()
a = random.randint(int(x), int(y))
t4["text"] = str(a)
print(a)


butt = tk.Button(win, text='开始', font="微软雅黑 15", width=10, height=2, command=lambda: [num(), ran()])
butt.grid(row=9, column=1)


win.mainloop()