【压强】模拟器 如何用python模拟压强变化 压强实验 初中物理

编程入门 行业动态 更新时间:2024-10-11 13:25:52

【<a href=https://www.elefans.com/category/jswz/34/1686669.html style=压强】模拟器 如何用python模拟压强变化 压强实验 初中物理"/>

【压强】模拟器 如何用python模拟压强变化 压强实验 初中物理

目录

 

一.介绍

二.视频

三.代码


 

一.介绍

用python可以制作可以模拟压强变化的模型,在一个双口瓶的一端用橡胶薄膜封闭,另一端加水观察橡胶薄膜的变化。

二.视频

首先我们看一下效果:

【压强】模拟器 如何用python模拟压强变化 压强实验 初

三.代码

源代码:

from tkinter import *
import tkinter as tk
import threading,os,timeclass basedesk():#底板def __init__(self, master):self.master = masterself.master.title("压强模拟器")self.master.configure(bg='#B1FFF9')self.master.geometry("1000x600")mainwindow(self.master)
class mainwindow():#主界面def __init__(self, master):self.master = masterself.window = tk.Frame(self.master, bg='#e5ffe5')self.window.place(x=0,y=0,width=1000,height=600)self.window.file=PhotoImage(file="menu.png")#用一张1000*600的图即可self.window.showname_label=tk.Label(self.window,image=self.window.file)self.window.showname_label.place(x=0,y=0,width=1000,height=600)self.window.enter_btn=tk.Button(self.window,text="开始",bg='#ffffe5',fg='#333399',font=("Helvetic", 60, "bold"),command=self.changetofunction).place(x=360, y=400,width=250, height=150)def changetofunction(self,):self.window.destroy()functionwindow(self.master)
class functionwindow():def __init__(self, master):self.master = masterself.window = tk.Frame(self.master, bg='#FFFFFF')self.window.place(x=0,y=0,width=1000,height=600)self.num=450self.num2=450self.window.bottlecanvas=Canvas(self.window,width=1000,height=600,bg='white')self.window.bottlecanvas.place(x=0,y=0)self.window.bottlecanvas.showaction_label=tk.Label(self.window.bottlecanvas,text="设置水位线",bg='#FFFFFF',fg='#000000',font=("Helvetic", 20, "bold"))self.window.bottlecanvas.showaction_label.place(x=0,y=50,width=200,height=50)self.window.slider=Scale(self.window.bottlecanvas,from_=400,to=0)self.window.slider.place(x=200,y=50,width=50, height=400)self.window.bottlecanvas.create_rectangle(500,50,600,450,fill="white")self.window.blue=self.window.bottlecanvas.create_rectangle(500,450,600,450,fill="blue")self.window.orange=self.window.bottlecanvas.create_arc(500,450,600,450,extent=180,start=180,fill="orange")self.thread=threading.Thread(target=self.detector)self.thread.start()def detector(self):while True:self.num=450-self.window.slider.get()self.num2=self.window.slider.get()/5self.window.bottlecanvas.coords(self.window.blue, 500, self.num, 600, 450)self.window.bottlecanvas.coords(self.window.orange, 500, 450-self.num2,600, 450+self.num2)if __name__ == '__main__':#主函数root = tk.Tk()root.resizable(False, False)basedesk(root)root.mainloop()os._exit(0)

 

 

更多推荐

【压强】模拟器 如何用python模拟压强变化 压强实验 初中物理

本文发布于:2024-02-06 04:16:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1746287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:压强   模拟器   如何用   物理   初中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!