Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Kivy:如何根据鼠标移动来增加和减少计数? 我希望能够在一个圆形旋钮的中间显示一个计数器值(0~360),然后根据OnthouthChyM迁事件增量和减量。到目前为止,我可以增加该值,而不管on_touch_移动(逆时针或顺时针),但不确定如何设置最大值,以及在on_touch_移动向下时如何减小该值。不确定如何在Kivy实现这一点。我做了一些研究,但不知道如何做,以下是我到目前为止的代码: from kivy.app import App from kivy.uix.label import Label from kivy.uix.widget import Widget from kivy.lang import Builder from kivy.animation import Animation from kivy.properties import NumericProperty from kivy.uix.boxlayout import BoxLayout from kivy.config import Config from kivy.core.window import Window Window.size = (781.274, 599) import math kv = ''' <Dial> canvas: PushMatrix Rotate: angle: root.angle origin: self.center Color: rgb: 255,0,0 Line: circle:self.center_x, self.center_y, 112, 19, self.angle % -180 width: 11 Color: rgb: 0,0,255 Line: circle:self.center_x, self.center_y, 112, 19, self.angle % 180 width: 11 Color: rgb: 255,255,255 Line: circle:self.center_x, self.center_y, 200, 500, self.angle % 45 width: 10 Color: rgba: .1, 1, .1, .9 Line: width: 2 circle: (self.center_x, self.center_y, min(self.width, self.height)/ 8.5,) Color: rgba: .502,.502,.502,1 Ellipse: pos: (850,410) size: (214,214) PopMatrix ''' Builder.load_string(kv) class Dial(Widget): def __init__(self, **kwargs): super(Dial, self).__init__(**kwargs) self.touch_move_count = 0 self.touch_move_Label = Label(text = " RPM", pos=(905,470), font_size=40, color=(10,10,255,1), halign="auto") self.update_count() self.add_widget(self.touch_move_Label) angle = NumericProperty(180) def update_count(self): self.touch_move_Label.text = str(self.touch_move_count) + "°F" def on_touch_down(self, touch): y = (touch.y - self.center[1]) x = (touch.x - self.center[0]) calc = math.degrees(math.atan2(y, x)) self.prev_angle = calc if calc > 0 else 360 + calc self.tmp = self.angle def on_touch_move(self, touch): y = (touch.y - self.center[1]) x = (touch.x - self.center[0]) calc = math.degrees(math.atan2(y, x)) new_angle = calc if calc > 0 else 360 + calc self.angle = self.tmp + (new_angle - self.prev_angle) % 360 self.touch_move_count +=1 self.update_count() class DialApp(App): def build(self): return Dial() if __name__ == "__main__": DialApp().run() 从kivy.app导入应用 从kivy.uix.label导入标签 从kivy.uix.widget导入widget 从kivy.lang导入生成器 从kivy.animation导入动画 从kivy.properties导入NumericProperty 从kivy.uix.boxlayout导入boxlayout 从kivy.config导入配置 从kivy.core.window导入窗口 Window.size=(781.274599) 输入数学 kv=''' 画布: 推矩阵 轮换: 角度:root.angle 来源:自我中心 颜色: rgb:255,0,0 行: 圆:自中心x,自中心y,112,19,自角度-180 宽度:11 颜色: rgb:0,0255 行: 圆:自中心x、自中心y、112、19、自角度%180 宽度:11 颜色: rgb:255255 行: 圆:self.center\u x,self.center\u y,200500,self.angle%45 宽度:10 颜色: rgba:.1,1,1,9 行: 宽度:2 圆圈: (自中心x,自中心y,最小值(自宽,自高)/8.5,) 颜色: rgba:.502.502.502,1 椭圆: 职位:(850410) 尺寸:(214214) 流行音乐 ''' 建筑商荷载(千伏) 类拨号(小部件): 定义初始(自我,**kwargs): 超级(拨号,自我)。\uuuuu初始化(**kwargs) self.touch\u move\u count=0 self.touch\u move\u Label=Label(text=“RPM”,pos=(905470),font\u size=40,color=(10,10255,1),halign=“auto”) self.update_count() self.add\u小部件(self.touch\u move\u标签) 角度=数值属性(180) def更新计数(自身): self.touch\u move\u Label.text=str(self.touch\u move\u count)+“华氏度” def on_触控向下(自身,触控): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) self.prev_angle=如果计算>0,则计算;否则360+计算 self.tmp=self.angle def on_touch_move(自我,触摸): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) 新角度=如果计算>0,则计算360+计算 self.angle=self.tmp+(新角度-自上角度)%360 self.touch\u move\u count+=1 self.update_count() 类拨号应用程序(应用程序): def生成(自): 返回拨号盘() 如果名称=“\uuuuu main\uuuuuuuu”: DialApp().run()命令_Python_Kivy - Fatal编程技术网 0,则计算;否则360+计算 self.tmp=self.angle def on_touch_move(自我,触摸): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) 新角度=如果计算>0,则计算360+计算 self.angle=self.tmp+(新角度-自上角度)%360 self.touch\u move\u count+=1 self.update_count() 类拨号应用程序(应用程序): def生成(自): 返回拨号盘() 如果名称=“\uuuuu main\uuuuuuuu”: DialApp().run()命令,python,kivy,Python,Kivy" /> 0,则计算;否则360+计算 self.tmp=self.angle def on_touch_move(自我,触摸): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) 新角度=如果计算>0,则计算360+计算 self.angle=self.tmp+(新角度-自上角度)%360 self.touch\u move\u count+=1 self.update_count() 类拨号应用程序(应用程序): def生成(自): 返回拨号盘() 如果名称=“\uuuuu main\uuuuuuuu”: DialApp().run()命令,python,kivy,Python,Kivy" />

Python Kivy:如何根据鼠标移动来增加和减少计数? 我希望能够在一个圆形旋钮的中间显示一个计数器值(0~360),然后根据OnthouthChyM迁事件增量和减量。到目前为止,我可以增加该值,而不管on_touch_移动(逆时针或顺时针),但不确定如何设置最大值,以及在on_touch_移动向下时如何减小该值。不确定如何在Kivy实现这一点。我做了一些研究,但不知道如何做,以下是我到目前为止的代码: from kivy.app import App from kivy.uix.label import Label from kivy.uix.widget import Widget from kivy.lang import Builder from kivy.animation import Animation from kivy.properties import NumericProperty from kivy.uix.boxlayout import BoxLayout from kivy.config import Config from kivy.core.window import Window Window.size = (781.274, 599) import math kv = ''' <Dial> canvas: PushMatrix Rotate: angle: root.angle origin: self.center Color: rgb: 255,0,0 Line: circle:self.center_x, self.center_y, 112, 19, self.angle % -180 width: 11 Color: rgb: 0,0,255 Line: circle:self.center_x, self.center_y, 112, 19, self.angle % 180 width: 11 Color: rgb: 255,255,255 Line: circle:self.center_x, self.center_y, 200, 500, self.angle % 45 width: 10 Color: rgba: .1, 1, .1, .9 Line: width: 2 circle: (self.center_x, self.center_y, min(self.width, self.height)/ 8.5,) Color: rgba: .502,.502,.502,1 Ellipse: pos: (850,410) size: (214,214) PopMatrix ''' Builder.load_string(kv) class Dial(Widget): def __init__(self, **kwargs): super(Dial, self).__init__(**kwargs) self.touch_move_count = 0 self.touch_move_Label = Label(text = " RPM", pos=(905,470), font_size=40, color=(10,10,255,1), halign="auto") self.update_count() self.add_widget(self.touch_move_Label) angle = NumericProperty(180) def update_count(self): self.touch_move_Label.text = str(self.touch_move_count) + "°F" def on_touch_down(self, touch): y = (touch.y - self.center[1]) x = (touch.x - self.center[0]) calc = math.degrees(math.atan2(y, x)) self.prev_angle = calc if calc > 0 else 360 + calc self.tmp = self.angle def on_touch_move(self, touch): y = (touch.y - self.center[1]) x = (touch.x - self.center[0]) calc = math.degrees(math.atan2(y, x)) new_angle = calc if calc > 0 else 360 + calc self.angle = self.tmp + (new_angle - self.prev_angle) % 360 self.touch_move_count +=1 self.update_count() class DialApp(App): def build(self): return Dial() if __name__ == "__main__": DialApp().run() 从kivy.app导入应用 从kivy.uix.label导入标签 从kivy.uix.widget导入widget 从kivy.lang导入生成器 从kivy.animation导入动画 从kivy.properties导入NumericProperty 从kivy.uix.boxlayout导入boxlayout 从kivy.config导入配置 从kivy.core.window导入窗口 Window.size=(781.274599) 输入数学 kv=''' 画布: 推矩阵 轮换: 角度:root.angle 来源:自我中心 颜色: rgb:255,0,0 行: 圆:自中心x,自中心y,112,19,自角度-180 宽度:11 颜色: rgb:0,0255 行: 圆:自中心x、自中心y、112、19、自角度%180 宽度:11 颜色: rgb:255255 行: 圆:self.center\u x,self.center\u y,200500,self.angle%45 宽度:10 颜色: rgba:.1,1,1,9 行: 宽度:2 圆圈: (自中心x,自中心y,最小值(自宽,自高)/8.5,) 颜色: rgba:.502.502.502,1 椭圆: 职位:(850410) 尺寸:(214214) 流行音乐 ''' 建筑商荷载(千伏) 类拨号(小部件): 定义初始(自我,**kwargs): 超级(拨号,自我)。\uuuuu初始化(**kwargs) self.touch\u move\u count=0 self.touch\u move\u Label=Label(text=“RPM”,pos=(905470),font\u size=40,color=(10,10255,1),halign=“auto”) self.update_count() self.add\u小部件(self.touch\u move\u标签) 角度=数值属性(180) def更新计数(自身): self.touch\u move\u Label.text=str(self.touch\u move\u count)+“华氏度” def on_触控向下(自身,触控): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) self.prev_angle=如果计算>0,则计算;否则360+计算 self.tmp=self.angle def on_touch_move(自我,触摸): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) 新角度=如果计算>0,则计算360+计算 self.angle=self.tmp+(新角度-自上角度)%360 self.touch\u move\u count+=1 self.update_count() 类拨号应用程序(应用程序): def生成(自): 返回拨号盘() 如果名称=“\uuuuu main\uuuuuuuu”: DialApp().run()命令

Python Kivy:如何根据鼠标移动来增加和减少计数? 我希望能够在一个圆形旋钮的中间显示一个计数器值(0~360),然后根据OnthouthChyM迁事件增量和减量。到目前为止,我可以增加该值,而不管on_touch_移动(逆时针或顺时针),但不确定如何设置最大值,以及在on_touch_移动向下时如何减小该值。不确定如何在Kivy实现这一点。我做了一些研究,但不知道如何做,以下是我到目前为止的代码: from kivy.app import App from kivy.uix.label import Label from kivy.uix.widget import Widget from kivy.lang import Builder from kivy.animation import Animation from kivy.properties import NumericProperty from kivy.uix.boxlayout import BoxLayout from kivy.config import Config from kivy.core.window import Window Window.size = (781.274, 599) import math kv = ''' <Dial> canvas: PushMatrix Rotate: angle: root.angle origin: self.center Color: rgb: 255,0,0 Line: circle:self.center_x, self.center_y, 112, 19, self.angle % -180 width: 11 Color: rgb: 0,0,255 Line: circle:self.center_x, self.center_y, 112, 19, self.angle % 180 width: 11 Color: rgb: 255,255,255 Line: circle:self.center_x, self.center_y, 200, 500, self.angle % 45 width: 10 Color: rgba: .1, 1, .1, .9 Line: width: 2 circle: (self.center_x, self.center_y, min(self.width, self.height)/ 8.5,) Color: rgba: .502,.502,.502,1 Ellipse: pos: (850,410) size: (214,214) PopMatrix ''' Builder.load_string(kv) class Dial(Widget): def __init__(self, **kwargs): super(Dial, self).__init__(**kwargs) self.touch_move_count = 0 self.touch_move_Label = Label(text = " RPM", pos=(905,470), font_size=40, color=(10,10,255,1), halign="auto") self.update_count() self.add_widget(self.touch_move_Label) angle = NumericProperty(180) def update_count(self): self.touch_move_Label.text = str(self.touch_move_count) + "°F" def on_touch_down(self, touch): y = (touch.y - self.center[1]) x = (touch.x - self.center[0]) calc = math.degrees(math.atan2(y, x)) self.prev_angle = calc if calc > 0 else 360 + calc self.tmp = self.angle def on_touch_move(self, touch): y = (touch.y - self.center[1]) x = (touch.x - self.center[0]) calc = math.degrees(math.atan2(y, x)) new_angle = calc if calc > 0 else 360 + calc self.angle = self.tmp + (new_angle - self.prev_angle) % 360 self.touch_move_count +=1 self.update_count() class DialApp(App): def build(self): return Dial() if __name__ == "__main__": DialApp().run() 从kivy.app导入应用 从kivy.uix.label导入标签 从kivy.uix.widget导入widget 从kivy.lang导入生成器 从kivy.animation导入动画 从kivy.properties导入NumericProperty 从kivy.uix.boxlayout导入boxlayout 从kivy.config导入配置 从kivy.core.window导入窗口 Window.size=(781.274599) 输入数学 kv=''' 画布: 推矩阵 轮换: 角度:root.angle 来源:自我中心 颜色: rgb:255,0,0 行: 圆:自中心x,自中心y,112,19,自角度-180 宽度:11 颜色: rgb:0,0255 行: 圆:自中心x、自中心y、112、19、自角度%180 宽度:11 颜色: rgb:255255 行: 圆:self.center\u x,self.center\u y,200500,self.angle%45 宽度:10 颜色: rgba:.1,1,1,9 行: 宽度:2 圆圈: (自中心x,自中心y,最小值(自宽,自高)/8.5,) 颜色: rgba:.502.502.502,1 椭圆: 职位:(850410) 尺寸:(214214) 流行音乐 ''' 建筑商荷载(千伏) 类拨号(小部件): 定义初始(自我,**kwargs): 超级(拨号,自我)。\uuuuu初始化(**kwargs) self.touch\u move\u count=0 self.touch\u move\u Label=Label(text=“RPM”,pos=(905470),font\u size=40,color=(10,10255,1),halign=“auto”) self.update_count() self.add\u小部件(self.touch\u move\u标签) 角度=数值属性(180) def更新计数(自身): self.touch\u move\u Label.text=str(self.touch\u move\u count)+“华氏度” def on_触控向下(自身,触控): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) self.prev_angle=如果计算>0,则计算;否则360+计算 self.tmp=self.angle def on_touch_move(自我,触摸): y=(touch.y-self.center[1]) x=(touch.x-self.center[0]) 计算=数学学位(数学atan2(y,x)) 新角度=如果计算>0,则计算360+计算 self.angle=self.tmp+(新角度-自上角度)%360 self.touch\u move\u count+=1 self.update_count() 类拨号应用程序(应用程序): def生成(自): 返回拨号盘() 如果名称=“\uuuuu main\uuuuuuuu”: DialApp().run()命令,python,kivy,Python,Kivy,我自己解决了这个问题。基本上写一个“如果”语句来确定新角度与初始角度的对比,如果大于增量+1,如果小于减量-1 我看到元素“蓝色”和“红色”如果通过触摸进行更改,您可以提供您希望获得的更多详细信息,因为基于触摸移动事件指向递增和递减是非常普遍的。感谢您的反馈。所以当我移动鼠标时,当前touch_计数返回增量值,但是,我想:1。设置一个最大值,一旦达到最大值2,触摸计数将停止。当鼠标以逆时针方向移动时,减小计数值不要向我解释变量(因为你可能会使用其他具有另一个概念的变量),但一般来说,当我以顺时针

我自己解决了这个问题。基本上写一个“如果”语句来确定新角度与初始角度的对比,如果大于增量+1,如果小于减量-1

我看到元素“蓝色”和“红色”如果通过触摸进行更改,您可以提供您希望获得的更多详细信息,因为基于触摸移动事件指向递增和递减是非常普遍的。感谢您的反馈。所以当我移动鼠标时,当前touch_计数返回增量值,但是,我想:1。设置一个最大值,一旦达到最大值2,触摸计数将停止。当鼠标以逆时针方向移动时,减小计数值不要向我解释变量(因为你可能会使用其他具有另一个概念的变量),但一般来说,当我以顺时针方向移动鼠标时,我希望看到计数器从0变为360,当我移动鼠标时,当计数达到360时,它就会停止。当我逆时针移动鼠标时,它应该从360变为0。好的,那么每个角度的变化都等于一个计数器值的变化?