当前位置: 首页 > news >正文

PythonStudio_圆的面积demo源代码

ps_圆的面积demo

# Powered By Python Studio, The best Python GUI IDE to download from glsite.com.
import os
from glcl import *class Form1(Form):def __init__(self, owner):self.Button3 = Button(self)self.Button2 = Button(self)self.Button1 = Button(self)self.SegoeGUI = Label(self)self.Edit1 = Edit(self)self.Label2 = Label(self)self.Label1 = Label(self)self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))self.Button3.OnClick = self.Button3Clickself.Button2.OnClick = self.Button2Clickself.Button1.OnClick = self.Button1Clickdef Button1Click(self, Sender):r=float(self.edit1.text)s=3.14*r**2self.label3.caption="面积:"+str(s)def Button2Click(self, Sender):self.Edit1.Clear( )self.Edit1.SetFocus( )self.label3.Caption = "面积:"def Button3Click(self, Sender):self.Close()

下面是用python TK库写的同样程序,对比一下代码量

import tkinter as tk
import mathdef calculate_area():try:radius = float(radius_entry.get())area = math.pi * radius ** 2area_label.config(text=f"{area}")except ValueError:area_label.config(text="请输入有效的半径值")def clear_fields():radius_entry.delete(0, tk.END)area_label.config(text="")root = tk.Tk()
root.title("圆面积计算程序")
root.geometry("300x200")
root.configure(bg="purple")# 设置标题
title_label = tk.Label(root, text="计算圆的面积", font=("Arial", 16), bg="purple", fg="white")
title_label.pack(pady=10)# 半径输入部分
radius_frame = tk.Frame(root, bg="purple")
radius_frame.pack()radius_label = tk.Label(radius_frame, text="半径:", bg="purple", fg="white")
radius_label.pack(side=tk.LEFT)radius_entry = tk.Entry(radius_frame, width=10)
radius_entry.pack(side=tk.LEFT)# 面积显示部分
area_frame = tk.Frame(root, bg="purple")
area_frame.pack()area_label_text = tk.Label(area_frame, text="面积:", bg="purple", fg="white")
area_label_text.pack(side=tk.LEFT)area_label = tk.Label(area_frame, text="", width=15)
area_label.pack(side=tk.LEFT)# 按钮部分
button_frame = tk.Frame(root, bg="purple")
button_frame.pack(pady=10)calculate_button = tk.Button(button_frame, text="计算", command=calculate_area)
calculate_button.pack(side=tk.LEFT, padx=5)clear_button = tk.Button(button_frame, text="清空", command=clear_fields)
clear_button.pack(side=tk.LEFT, padx=5)exit_button = tk.Button(button_frame, text="退出", command=root.quit)
exit_button.pack(side=tk.LEFT, padx=5)root.mainloop()
http://www.jsqmd.com/news/2961/

相关文章:

  • HarmonyOS 5分布式数据同步实战:跨设备待办事项应用
  • 深入理解HarmonyOS 5的AVSession:构建跨设备媒体播放器
  • HT-AD4PS-1+ 一分四射频功分器:1-500 MHz 小尺寸/低插损,通信、医疗全能打
  • HarmonyOS资源管理与访问:多分辨率与多语言适配
  • 面试官:为什么没有虚拟线程池?
  • 润生软件简介:以“重构与共生”引领商业未来
  • Python 并发编程
  • 安装pyautogui时与setuptool时冲突报错-module setuptools.dist has no attribute check_test_suite
  • 牛客周赛 Round 110 题解
  • 统计机器学习经典分类算法MATLAB实现
  • 从安装到中文界面,一文带你玩转 DaVinci Resolve 20(零基础也能搞定)
  • 靶场1
  • 299、已凉
  • linux手动安装阿里云Logtail采集Nginx访问日志
  • WPF的数据绑定之通知修改
  • 古代史
  • matlab运行时遇到的license问题
  • HarmonyOS 5.0+ 安全加密与数据存储最佳实践指南
  • EV论文修改工作
  • HarmonyOS之设备硬件能力调用:传感器、蓝牙与定位
  • 基于HarmonyOS SDK开放能力的微博社交体验构建实践
  • web三维
  • HarmonyOS 多线程编程:Worker 使用与性能优化指南
  • 贝叶斯定理简单解释
  • B端界面设计的核心逻辑:效率优先还是体验优先?
  • 质数(埃氏筛、欧拉筛)
  • HarmonyOS数据持久化:Preferences轻量级存储实战
  • HarmonyOS服务卡片开发:动态卡片与数据绑定实战指南
  • 【CV】GAN代码解析:base_model.py
  • 有理数类的问题回答