from tkinter import * root = Tk() root.geometry("300x540") root.title("保温材料") kind_hcc={"岩棉":0.04,"玻璃棉":0.042,"聚苯乙烯泡沫":0.033,\ "聚氨酯泡沫":0.024,"硅酸铝":0.045,"泡沫混凝土":0.08} def calculate(): U = 0.8 m1 = float(m1_entry.get()) m2 = float(m2_entry.get()) m3 = float(m3_entry.get()) t1 = float(t1_entry.get()) t2 = float(t2_entry.get()) type_name = type_var.get() b_w = float(b_w_entry.get()) def kind(name): def wide(w): return kind_hcc[name]/w return wide f=kind(type_name) print(f(b_w))#计算建筑材料的导热系数 A = t2-t1 #温度差 B = m1*U*A #窗户导热损失 C = m2*f(b_w)*A #墙体导热损失 D = m3*f(b_w)*A #屋顶导热损失 Z = abs(B)+abs(C)+abs(D) #总导热损失 if Z > 50: result_label.config(text="总导热损失为:{}".format(Z), fg="red") result_label2.config(text="材料不合适该建筑类型", fg="red") else: result_label.config(text="总导热损失为:{}".format(Z), fg="blue") result_label2.config(text="材料适合该建筑类型", fg="blue") m1_label = Label(root, text="窗户面积(单位:平方米):") m1_entry = Entry(root) m1_label.pack() m1_entry.pack() m2_label = Label(root, text="墙体面积(单位:平方米):") m2_entry = Entry(root) m2_label.pack() m2_entry.pack() m3_label = Label(root, text="屋顶面积(单位:平方米):") m3_entry = Entry(root) m3_label.pack() m3_entry.pack() t1_label = Label(root, text="室内温度(单位:℃):") t1_entry = Entry(root) t1_label.pack() t1_entry.pack() t2_label = Label(root, text="设计供暖温度(单位:℃):") t2_entry = Entry(root) t2_label.pack() t2_entry.pack() type_label = Label(root, text="请选择建筑材料:") type_label.pack() type_var = StringVar() type_var.set("岩棉") for name in kind_hcc: radio = Radiobutton(root, text=name, variable=type_var, value=name) radio.pack() b_w_label = Label(root, text="请输入材料厚度(单位:米):") b_w_entry = Entry(root) b_w_label.pack() b_w_entry.pack() button = Button(root, text="确定", command=calculate) result_label = Label(root, text="") result_label2 = Label(root, text="") button.pack(pady=10) result_label.pack() result_label2.pack()
时间: 2024-02-26 13:53:31 浏览: 20
这段代码是一个基于Tkinter的GUI程序,用于计算建筑材料的导热系数和总导热损失。用户需要输入窗户、墙体和屋顶的面积,室内温度、设计供暖温度和建筑材料的厚度,并选择建筑材料的种类。程序会根据用户输入的数据计算导热系数和总导热损失,并给出是否适合该建筑类型的建议。其中,建筑材料的种类和厚度对导热系数的计算起到了重要作用。
相关问题
from Tkinter import * Root=Tk() Root.mainloop()
I'm sorry, as an AI language model, I cannot execute code directly on your computer. Can you please provide more context or information on what you are trying to achieve?
from tkinter import * root = Tk() root.title('Timer') # root.state('zoomed') sec = 0 def tick(): global sec sec += 1 time['text'] = sec # Take advantage of the after method of the Label time.after(1000, tick) time = Label(root, fg='green') time.pack() Button(root, fg='blue', text='Start', command=tick).pack() root.mainloop() 如何点击按钮退出并重置时间
要实现点击按钮退出并重置时间,可以在按钮的命令函数中添加退出和重置时间的功能。以下是修改的代码示例:
```python
from tkinter import *
root = Tk()
root.title('Timer')
sec = 0
timer_running = False
def tick():
global sec
sec += 1
time['text'] = sec
# Take advantage of the after method of the Label
if timer_running:
time.after(1000, tick)
def start_timer():
global timer_running
timer_running = True
tick()
def stop_timer():
global timer_running, sec
timer_running = False
sec = 0
time['text'] = sec
time = Label(root, fg='green')
time.pack()
start_button = Button(root, fg='blue', text='Start', command=start_timer)
start_button.pack()
stop_button = Button(root, fg='red', text='Stop', command=stop_timer)
stop_button.pack()
root.mainloop()
```
在上面的代码中,我们添加了一个新的按钮 `Stop`,并且创建了一个 `stop_timer` 函数来停止计时器并重置时间。当点击 `Stop` 按钮时,`timer_running` 变量会被设置为 `False`,计时器停止,并且时间被重置为 0。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)