from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.stacklayout import StackLayout
from kivy.uix.modalview import ModalView
from kivy.config import Config
from ai import Ai
from random import randint
class TicTacToe(StackLayout): #StackLayout explanation: https://kivy.org/docs/api-kivy.uix.stacklayout.html
states = [1, 2, 3, 4, 5, 6, 7, 8, 9]
choices = ["X","O"]
def __init__(self, **kwargs):
super(TicTacToe, self).__init__(**kwargs)
self.init_players();
for x in range(9): # range() explanation: http://pythoncentral.io/pythons-range-function-explained/
bt = Button(text=' ', font_size=200, width=200, height=200, size_hint=(None, None), id=str(x+1))
bt.bind(on_release=self.btn_pressed)
self.add_widget(bt)
view = ModalView(auto_dismiss=False)
view.add_widget(Label(text='Hello world'))
view.open()
def init_players(self):
rand_choice = randint(0,1);
self.bot = Ai(self.choices[rand_choice]);
self.player = self.choices[0] if rand_choice == 1 else self.choices[1]
def btn_pressed(self, button):
button.text="X"
self.states[int(button.id)-1] = "X"
print(self.states)
class MyApp(App):
title = 'Tic Tac Toe'
def build(self):
Config.set('graphics', 'width', '600')
Config.set('graphics', 'height', '600')
return TicTacToe()
if __name__ == '__main__':
MyApp().run()
これは私のやりたいことですが、これはModalViewの代わりに "こんにちは、あなたはXでこのゲームを始めました"というポップアップがあります。問題は、Popal(ModalViewも)を使用すると、ウィンドウがすべてのボタンの背後に表示されていることです。ポップアップをクリックした後に呼び出すと、ポップアップが正しく表示されますが、これをWindowの初期化で実行します。Kivy Pythonのポップアップ - 前に表示
のようなあなたのビューを開いた後、ポップアップを開く示唆? – Juggernaut
うん、まさに私が欲しいものです。 – LimoTuz