私と私の友達はkivyでゲームをコーディングしようとしていましたが、この時点で固まっています。他のボタンを押すことでボタンの色やイメージを変更することができます。 ゲームはチェス盤にあり、我々はFox &ハウンドゲームをしようとしているので、ユーザーがハウンドを押すと、チェス盤の2ブロックが点灯してどこに移動できるかを示し、1つを押してそれらのうち、デ・ハウンドのイメージを押し付けられたものに変えてください。Kivyプログラミング、別のボタンを押してボタンの色やイメージを変更する方法
ここにコードがありますが、これで私を助けてくれることを願っています。ありがとう。
from kivy.app import App
from kivy.graphics import *
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
from kivy.uix.popup import Popup
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.stacklayout import StackLayout
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.config import Config
Window.size = (800, 800)
intento = 0
nroboton= [0,0]
class MainWindow(GridLayout): # main class
def popbtns(self):
i = 3
self.add_widget(Label(text=' '))
self.add_widget(Btn(id=str(i+3), size=(100, 100), background_color=(0,0,0,1)))
i = i - 1
class Btn(Button): # button class
def on_release(self):
print('self.pos= ' + str(self.id))
def on_press(self):
global intento
if(intento == 1):
nroboton[1] = self.id
print('moviendose de ' + str(nroboton[0]) + 'a ' + str(nroboton[1]))
intento = 0
else:
nroboton[0] = self.id
intento = 1
print('llamada ssh ' + str(self.id))
class But(Button):
def new(self):
self.background_color=(0,250,0,1)
class Zorro(Button): # button class
def on_release(self):
print('self.pos= ' + str(self.id))
def on_press(self):
global intento
if(intento == 1):
nroboton[1] = self.id
print('moviendose de ' + str(nroboton[0]) + 'a ' + str(nroboton[1]))
intento = 0
else:
nroboton[0] = self.id
intento = 1
print('llamada ssh ' + str(self.id))
class MainApp(App):
def build(self):
main = MainWindow(cols=3, rows=1)
self.root = main # don't use global!
# make background
with main.canvas:
Rectangle(pos=main.pos, size=(10000,10000))
# populate gridlayout with Buttons
#main.add_widget(Debug(text='debug', background_color=(1, 0, 0, 1)))
main.popbtns()
# print position of buttons...
Clock.schedule_once(self.delayed_function, 0.1)
def delayed_function(self, dt):
self.print_buttons_pos()
def print_buttons_pos(self):
for child in self.root.children:
print(str(child) + ' pos is ' + str(child.id))
if __name__ == "__main__":
MainApp().run()
次に、ハウンズとフォックスのイメージを示します。 Hound Fox
[OK]をので、これは、私はそれを減らすことができるすべてであることが
[mcve]に減らしてください。そうであるように、多くの追加情報があります。つまり、2つのボタンが付いたkivyアプリを持っているだけです。 –
完了!少なくとも、私はそれを減らそうとしました。 –
まだありました(* way * smaller。)(https://gist.github.com/waynew/16818fc29de61d4f41118f5c3b6dea4e) –