|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 wqiori 于 2023-3-6 20:53 编辑
1.导语
作者在上小学6年级,正在学圆柱和圆锥,但π(3.14)这个小数算起来就是个煎熬,所以我做出了这个东西
2.正文
本作品是用tkinter写的,欢迎借鉴
我写了两个版本,一个是可以保存txt文件,想打印保存下来的鱼油可以使用(我起的名字是n×π.py);另一个则是临时性较强,更多只是为了扫一眼(我起的名字是n×π_plus.py)
代码如下:
- #n×π.py
- from tkinter import *
- from tkinter import filedialog, dialog
- root = Tk()
- root.title('计算n×π')
- root.geometry('400x75')
- var1 = IntVar()
- var1.set(100)
- Label(root, text='从1到 ×π', font=('楷体', 13)).place(x=25, y=20)
- Entry(root, font=('JetBrains Mono', 10), fg='blue', textvariable=var1).place(x=75, y=22)
- def start():
- file = filedialog.asksaveasfile(mode='w', defaultextension='.txt')
- file_name = file.name
- f = open(file_name, 'w')
-
- def 让我看看():
- global file
-
- text = Tk()
- text.title(file_name)
-
- sb = Scrollbar(text)
- sb.pack(side=RIGHT, fill=Y)
-
- txtfile = open(file_name, 'r')
-
- theText = Text(text, height=50, width=40, font=('微软雅黑', 20), yscrollcommand=sb.set)
- theText.pack()
-
- theText.insert(INSERT, txtfile.read())
-
- sb.config(command=theText.yview)
-
- mainloop()
-
- for i in range(1, int(var1.get())+1):
- f.write(str(i) + ' × 3.14 = ' + str(i * 314 / 100) + '\n')
-
- f.close()
- var2 = []
-
- Button(root, font=('楷体', 15), text='让我看看', command=让我看看).place(x=400, y=15)
- root.geometry('500x75')
- Button(root, font=('楷体', 15), text='开始计算', command=start).place(x=300, y=15)
- root.mainloop()
复制代码
图片:
- #n×π_plus.py
- from tkinter import *
- root = Tk()
- root.title('计算n×π')
- root.geometry('400x75')
- var1 = IntVar()
- var1.set(100)
- Label(root, text='从1到 ×π', font=('楷体', 13)).place(x=25, y=20)
- Entry(root, font=('JetBrains Mono', 10), fg='blue', textvariable=var1).place(x=75, y=22)
- def start():
- def 让我看看():
- text = Tk()
-
- sb = Scrollbar(text)
- sb.pack(side=RIGHT, fill=Y)
-
- theText = Text(text, height=50, width=40, font=('微软雅黑', 20), yscrollcommand=sb.set)
- theText.pack()
-
- var2 = []
- for i in range(1, int(var1.get())+1):
- var2.append(str(i) + ' × 3.14 = ' + str(i * 314 / 100) + '\n')
-
- for i in range(len(var2)):
- theText.insert(INSERT, var2[i])
-
- sb.config(command=theText.yview)
-
- mainloop()
- Button(root, font=('楷体', 15), text='让我看看', command=让我看看).place(x=400, y=15)
- root.geometry('500x75')
- Button(root, font=('楷体', 15), text='开始计算', command=start).place(x=300, y=15)
- root.mainloop()
复制代码
图片:
下面是打包好的exe文件,欢迎使用!
蓝奏链接(n×π.exe):
https://wwxl.lanzoul.com/ih0vB0pgmvyj
密码:9bw8
蓝奏链接(n×π_plus.exe)
https://wwxl.lanzoul.com/i7itg0pgmxcj
密码:anok
|
评分
-
查看全部评分
|