猕猴桃提取密码_我在猕猴桃中的第一个应用

2023-05-16

猕猴桃提取密码

A simple calculator

一个简单的计算器

为什么要使用计算器?(Why calculator?)

If you have started learning kivy and your all basic concepts related to kivy are cleared, then you will be excited to build your very first app and looking for a basic idea to build an app.

如果您已经开始学习kivy,并且所有与kivy相关的基本概念都已被清除,那么您将很高兴构建自己的第一个应用程序并寻找构建应用程序的基本想法。

My suggestion to build a basic app like a calculator because it is easy to build a calculator for a person who’s new to the framework and as well as it will help you understand various new concepts related to the kivy framework.

我建议构建一个像计算器这样的基本应用程序,因为它很容易为刚接触该框架的人构建一个计算器,并且它将帮助您理解与kivy框架相关的各种新概念。

And one of the main reasons i chose calculator is that when we fail to do our first task successfully we tend to drop learning the language. So my advice is to start with an easy task that can be completed and that will motivate you to learn this framework further, as small achievement gives you great motivation to strive for more

我选择计算器的主要原因之一是,当我们未能成功完成第一个任务时,我们倾向于放弃学习该语言。 因此,我的建议是从一个容易完成的任务开始,这将激发您进一步学习该框架的能力,因为小的成就会给您很大的动力去争取更多

建立有吸引力的界面(Build an attractive Interface)

Before building your application interface, you must keep in mind that your application interface should look attractive and also be simple enough which can be operated by a non-technical user.

在构建应用程序界面之前,必须记住,您的应用程序界面应该看起来很吸引人,并且也足够简单,可以由非技术用户进行操作。

开始建设 (Start building)

We all are very much familiar with a calculator and must know that a calculator interface consist of numbers of buttons like count(0–9), operators(+,_,*,/), etc.

我们都非常熟悉计算器,并且必须知道计算器界面由许多按钮组成,例如count(0–9),运算符(+,_,*,/)等。

问题 (Problem)

Now, most of the newbies will start creating each button separately by writing each button object but this will increase the lines of code and will make your program complex.

现在,大多数新手将通过编写每个按钮对象来分别创建每个按钮,但这将增加代码行,并使程序复杂。

如何解决这个问题呢? (How to solve this problem?)

If you have experience of any programming language you must be aware of the loop concept and we are going to apply that concept here.By using for loop we can create multiple buttons by writing a few lines of code and can set different parameters for each button separately.

如果您有任何编程语言的经验,您必须了解循环概念,我们将在此处应用该概念。通过使用for循环,我们可以通过编写几行代码来创建多个按钮,并且可以为每个按钮设置不同的参数分别。

let me show you how it will work:

让我向您展示它如何工作:

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.core.window import Window#window size
w,h=Window.size#class for first screenclass Display(FloatLayout):
string=""
def __init__(self,*args):
super().__init__(*args)
self.text_field=TextInput(font_size=60,hint_text="Enter the values here",text="",size_hint=(0.8,0.05),pos_hint={'x':0.1,'y':0.85})
self.add_widget(self.text_field)

btn_list=['C','(',')','/','7','8','9','*','4','5','6','+','1','2','3','-','0','','.','=']
Y=0.5
X=0.025
n=1
for i in range(20):
if n==18:
pass
else:
self.btn=Button(text=btn_list[i],size_hint=(0.2,0.1),pos_hint={'x':X,'y':Y},)
self.add_widget(self.btn)
self.btn.background_color = (1, 1, 1, 1)
self.btn.color=(0,0,0,1)
self.btn.font_size=w*0.05
self.btn.bind(on_press=self.calculation)

if n%4==0:
Y-=0.125
X=0.025
self.btn.background_color=(1,0.49,0.31,1)
self.btn.color=(1,1,1,1)
else:
X+=0.25

if n==17:
self.btn.size_hint_x=0.45
if n==20:
self.btn.background_color=(0,1,0,1)

n+=1
def calculation(self,instance):
pass

#Main class
class calci(App):
def build(self):
return Display()

calci().run()

Output

输出量

Explanation

说明

In the above code, we have created one text field where all the calculations part will be displayed.

在上面的代码中,我们创建了一个文本字段,其中将显示所有计算部分。

And then we’ve created a list carrying the button name we want to add in the interface and then started a for loop in which button is being created one by one but we need to put text and position as variable because every button will have different text as well as different position. As you can see we are putting text from the above list that we have created and position is also varying from button to button. We have also given different colours. Like this different parameter is passed to different buttons.

然后,我们创建了一个列表,其中包含要在界面中添加的按钮名称,然后启动for循环,在该循环中逐个创建按钮,但是我们需要将文本和位置作为变量,因为每个按钮都有不同的位置文字以及其他位置。 如您所见,我们从上面创建的列表中放入文本,并且位置在每个按钮之间也有所不同。 我们还提供了不同的颜色。 像这样,将不同的参数传递给不同的按钮。

Now, these all buttons should perform a function but if you have noticed that we have bound all the buttons with the same function. So how will the function differentiate which button is clicked by the user?

现在,所有这些按钮都应该执行功能,但是如果您注意到我们已经将所有按钮绑定为相同的功能。 那么该功能如何区分用户单击哪个按钮?

For that, you will have to understand the concept of instance.

为此,您将必须了解实例的概念。

什么是实例? (What is an instance?)

When we bind a button with a function then it will send all its information like its text, size, position, etc. on doing that binded action.

当我们将按钮与函数绑定时,它将在执行绑定操作时发送其所有信息,如文本,大小,位置等。

And all of the information will be store as an instance in that function, so you have to mention a parameter in that function as instance or by any other name.

并且所有信息将作为实例存储在该函数中,因此您必须在该函数中以实例或任何其他名称提及一个参数。

Now, we will prepare that function so that our application will work according to the demand of the user.

现在,我们将准备该功能,以便我们的应用程序可以根据用户的需求运行。

   def calculation(self,instance):
a=instance.text
if a=="=":
try:
self.string=self.text_field.text
self.text_field.text=str(eval(self.string))
self.string=self.text_field.text
except SyntaxError:
self.text_field.text="syntax error!"
self.string=""
except TypeError:
self.text_field.text="pass wrong input!"
self.string=""
except NameError:
self.text_field.text="syntax error!"
self.string=""
except:
self.text_field.text="syntax error!"
self.string=""
elif a=="C":
self.string=self.string[0:-1]
self.text_field.text=self.string
else:
self.string+=a
self.text_field.text=self.string

Replace this function with the function of the above code and your application will start working.

用上面的代码替换此函数,您的应用程序将开始运行。

Output

输出量

Explanation

说明

So what’s going on in this function is, initially, the function is identifying which button is clicked by the user by checking it’s text which is present in instance parameter.And then if the equal button is clicked, the function is picking the text field input and solving it using an inbuilt function in python which is eval().

因此,此函数的功能是,首先,该函数通过检查实例参数中存在的文本来识别用户单击了哪个按钮,然后如果单击了相等按钮,则该函数将选择文本字段输入并使用python中的内置函数eval()来解决它。

eval() function is used to solve the mathematical expression by BODMAS rule.If it will face any kind of exception then it will be handled by exception handling and will show output according to the type of error.

eval()函数用于通过BODMAS规则求解数学表达式,如果遇到任何异常,将通过异常处理进行处理,并根据错误的类型显示输出。

If the Clear button is clicked, it will decrease the text field value by one letter.Else every button will do the same thing that adds their value in the text field. Similarly like this you can allot functioning to every button.

如果单击清除按钮,则会将文本字段的值减少一个字母,否则每个按钮都会执行相同的操作,将其值添加到文本字段中。 同样,您可以为每个按钮分配功能。

That’s how this function works and calculates the values. In this way you can build your own calculator and add more functions to it like trigonometry, power, root etc and also you can make it more attractive.

这就是该函数的工作方式并计算值。 这样,您可以构建自己的计算器并为其添加更多功能,例如三角函数,幂,根等,也可以使其更具吸引力。

Previous article: Hello, in the world of kivy

上一篇:您好,在猕猴桃世界

For more such posts, do follow out our Publication:https://medium.com/tek-society

有关更多此类帖子,请遵循我们的出版物: https : //medium.com/tek-society

Also do clap! It encourages me to write better!

还拍手! 它鼓励我写得更好!

Thank you!

谢谢!

翻译自: https://medium.com/tek-society/my-first-application-in-kivy-bdf2a560287f

猕猴桃提取密码

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

猕猴桃提取密码_我在猕猴桃中的第一个应用 的相关文章

  • MyEclipse配置Tomcat 7

    1 打开步骤 xff1a 窗口 gt 首选项 gt MyEclipse gt Servers gt Tomcat gt Tomcat 7 x 2 配置自己本地的Tomcat 7版本 3 关闭MyEclipse自带的Tomcat服务器 4 启
  • mysql之模糊查询的方法

    Mysql模糊查询正常情况下在数据量小的时候 xff0c 速度还是可以的 xff0c 但是不容易看出查询的效率 xff0c 在数据量达到百万级 xff0c 千万级的甚至亿级时mysql查询的效率是很关键的 xff0c 也是很重要的 一 一般
  • Spring Cloud限流详解

    Spring Cloud限流详解 Spring Cloud Spring Cloud 2017 12 01 在高并发的应用中 xff0c 限流往往是一个绕不开的话题 本文详细探讨在Spring Cloud中如何实现限流 在Zuul上实现限流
  • 如何释放linux的内存

    你们知道怎么释放linux的内存吗不知道的话跟着学习啦小编一起来学习怎么释放linux的内存 释放linux的内存的步骤 Linux下操作频繁时 xff0c 物理内存会被快速用完 xff0c 当操作结束后 xff0c 物理内存没有被正常的释
  • docker修改镜像名称以及tag版本

    docker tag 镜像ID 镜像名称 tag版本信息 docker tag 8ef375298394 mysql v5 7
  • 跨域的五种解决方案详解

    1 跨域解决方案一 cors技术 CORS 全称cross origin resource share xff08 资源共享 xff09 工作原理 xff1a 服务器 在返回响应报文的时候 xff0c 在响应头中 设置一个允许的header
  • MySQL 日期时间类型精确到毫秒

    MySQL 常用的日期时间类型常用的是datetime timestamp 其中datetime占用5个字节 xff08 有些文档中说占用8个字节是不对的 xff0c 默认也不会保存毫秒 xff09 DATETIME和TIMESTAMP两种
  • Spring Boot——Thymeleaf

    哈喽 xff01 大家好 xff0c 我是 xff0c 一位上进心十足的 Java领域博主 xff01 的写作风格 xff1a 喜欢用 通俗易懂 的文笔去讲解每一个知识点 xff0c 而不喜欢用 高大上 的官方陈述 博客的领域是 面向后端技
  • 详细nginx配置websocket的wss协议

    需求 xff1a 小程序连接websocket xff0c 必须使用wss协议 nginx配置websocket以及wss协议 其实wss协议就是使用了ssl协议的域名所自带的协议 xff0c 所以wss协议需要域名来进行socket连接
  • Java面试宝典(超级详细)

    一 Java 基础 1 JDK 和 JRE 有什么区别 xff1f JDK xff1a Java Development Kit 的简称 xff0c java 开发工具包 xff0c 提供了 java 的开发环境和运行环境 JRE xff1
  • VNCServer卡死处理办法

    通过VNC连接远程Linux服务器 xff0c 一段时间后 xff0c 远程界面卡死 xff0c 不能操作 解决办法 xff1a 重启vncserver服务 通过终端远程ssh到服务器 1 xff09 查看vncserver命令用法 xff
  • Lottie进阶和原理分析

    简介 Lottie是aribnb发布的开源库 xff0c 它可以将AE制作的动画在Android iOS和RN代码中渲染出来 Lottie的功能及其强大 xff0c 只需要设计师使用AE设计动画 xff0c 用bodymovin导出 xff
  • 前端都应该了解的 NodeJs 知识及原理浅析

    node js 初探 Node js 是一个 JS 的服务端运行环境 xff0c 简单的来说 xff0c 它是在 JS 语言规范的基础上 xff0c 封装了一些服务端的运行时对象 xff0c 让我们能够简单实现非常多的业务功能 如果我们只使
  • 网站安全检测被 提示该网站内容被禁止访问

    很多建站公司都在使用Kindeditor开源的图片上传系统 xff0c 该上传系统是可视化的 xff0c 采用的开发语言支持asp aspx php jsp 几乎支持了所有的网站可以使用他们的上传系统 xff0c 对浏览器的兼容以及手机端也
  • 10个经典程序员代码技能,学会一个就能月薪上万!

    今天小编我给大家整理了一份10个程序员常用的代码简写技术 xff0c 看懂一种是入门 xff0c 全懂就是大神 xff0c 你能知道几个呢 xff1f 这篇文章分享之前我还是要推荐下我自己的前端群 xff1a 733581373 xff0c
  • android 9.0 中关于OTA 升级的注意事项

    droid 分区查看 emcc 7 x 8 x 一 要确定有多少个分区 xff1f 详细解析 xff1a major 表示主设备号 minor 表示次设备号 blocks 表示的是block的数目 name 是指的设备名称 例如 xff1a
  • ubuntu设置虚拟显示器且远程连接

    版本 ubuntu 20 04 安装虚拟显示器 sudo apt install xserver xorg core hwe 18 04 sudo apt install xserver xorg video dummy hwe 18 04
  • FFmpeg视频解码流程详解及demo

    本文主要讲解FFmpeg的视频解码具体流程 xff0c API使用 xff0c 以及相关结构体介绍 最后再以一个非常简单的demo演示将一个mp4格式的视频文件解码为原始数据yuv文件 FFmpeg解码流程有2套API接口 xff0c 本文
  • crontab执行jar包时,Could not find or load main class(找不到或者加载不到主类)

    crontab执行jar包时 xff0c Could not find or load main class 找不到或者加载不到主类 在linux服务器上配置crontab时 xff0c 子账户执行不报错 xff0c 但是切到root账户
  • 检测Android模拟器

    package com lisn check emulator lib import java io BufferedInputStream import java io BufferedOutputStream import java i

随机推荐