ok so my goal is to have a very clean slate as I like it when my code is organized, but that has also caused me too much trouble.
I have 3 .py files:
Main.py:
# imports
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class DiceRollScreen(Screen):
pass
class CoinFlipScreen(Screen):
pass
class Calcu(Screen):
pass
class TouchScreenTest(Screen):
pass
class BinaryToTxt(Screen):
pass
class TxtToBinary(Screen):
pass
class MainScreen(Screen):
pass
class WindowManager(ScreenManager):
pass
BLD = Builder.load_file('KV_FILE.kv')
class QuickAppz(App):
def __init__(self, **kwargs):
super(QuickAppz, self).__init__(**kwargs)
def build(self):
return BLD
pass
if __name__ == "__main__":
QuickAppz().run()
function.py
def DiceRoll(start_num=0, end_num=6, modifier=0):
import random
DiceValue = random.randint(start_num, end_num)
FinalValue = DiceValue + modifier
int(FinalValue)
return FinalValue
def CoinFlip():
import random
global Heads, Tails, CoinValue
CoinValue = random.randint(1, 2)
int(CoinValue)
if CoinValue == 1:
Heads = True
Tails = False
elif CoinValue == 2:
Heads = False
Tails = True
else:
print("ERROR")
KV_FILE.kv
# Pre-Styling
# Main Styling
WindowManager:
MainScreen:
DiceRollScreen:
CoinFlipScreen:
Calcu:
TouchScreenTest:
BinaryToTxt:
TxtToBinary:
<MainScreen>:
name: "Main"
GridLayout:
cols: 2
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'Images\\Background 1.png'
Button:
text: "Calculator"
on_release: app.root.current = "Calcu"
background_color: .2,.2,.2,.8
Button:
text: "Dice Simulator"
on_release: app.root.current = "Dice"
background_color: .2,.2,.2,.8
Button:
text: "Coin Flip"
on_release: app.root.current = "Coin"
background_color: .2,.2,.2,.8
Button:
text: "Binary To Text"
on_release: app.root.current = "BTT"
background_color: .2,.2,.2,.8
Button:
text: "Text To Binary"
on_release: app.root.current = "TTB"
background_color: .2,.2,.2,.8
Button:
text: "Touch Screen Test"
on_release: app.root.current = "TST"
background_color: .2,.2,.2,.8
<Calcu>:
name: "Calcu"
Label:
text: "Hello World"
Button:
text: "GO BACK"
on_release: app.root.current = "Main"
<CoinFlipScreen>:
name: "Coin"
Label:
text: "Hello World"
Button:
text: "GO BACK"
on_release: app.root.current = "Main"
<DiceRollScreen>:
name: "Dice"
Label:
text: "Hello World"
Button:
text: "GO BACK"
on_release: app.root.current = "Main"
id: DiceRoller
<BinaryToTxt>:
name: "BTT"
Label:
text: "Hello World"
Button:
text: "GO BACK"
on_release: app.root.current = "Main"
<TxtToBinary>:
name: "TTB"
Label:
text: "Hello World"
Button:
text: "GO BACK"
on_release: app.root.current = "Main"
<TouchScreenTest>:
name: "TST"
Label:
text: "Hello World"
Button:
text: "GO BACK"
on_release: app.root.current = "Main"
and one more extra.py files is there but there is no use for it yet
so my question is in function.py there is a function called CoinFlip and in KV_FILE.kv there is a button that I want to assign the CoinFLip Function
You just need to import the CoinFlip()
method in your kv
file like this:
#: import CoinFlip function.CoinFlip
And then you can use it with a Button
, like this:
Button:
text: "Coin Flip"
on_release:
app.root.current = "Coin"
CoinFlip()
background_color: .2,.2,.2,.8