1

i have an app, that in the future, will be a cards game counter, but right now its nowhere near that stage, anyways, i have 3 files, main.py, screens.kv,screens2.kv(which doesnt have anything in it) now i also got a picture, and its a button, each time its pressed, for test it writes down "pressed", i've been on this for at least 2 hours and cant figure out how to make the button appear when i press "Start Pasmar" (Pasmar is the name of the game in future), all it brings up is a blank screen after i press the button, but i did replace them and it only showed the button, nothing else.

This my current code:

#-*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.properties import ObjectProperty
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.tabbedpanel import TabbedPanelHeader
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from functools import partial
from kivy.base import runTouchApp
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.popup import Popup
import sys
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior 
from kivy.lang import Builder
from kivy.base import runTouchApp
import random
import time
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.properties import ObjectProperty, NumericProperty

import time
import threading



class ScreensApp(App):  
    def build(self):  
        return RootWidget()


class ScreenOne(Screen):
    pass


class ScreenTwo(Screen):

    def __init__(self, **kwargs):
        super(ScreenTwo, self).__init__(**kwargs)


class RootWidget(FloatLayout):
    pass

class ImageButton(ButtonBehavior, Image):  
    def on_press(self):
        print ('pressed')


    def displayScreenThenLeave(self):
        self.changeScreen()

    def changeScreen(self):
        if self.manager.current == 'screen1':
            self.manager.current = 'screen2'
        else:
            self.manager.current = 'screen1'


class Manager(ScreenManager):

    screen_one = ObjectProperty(None)
    screen_two = ObjectProperty(None)


class ScreensApp(App):

    def build(self):
        m = Manager(transition=NoTransition())
        return m

if __name__ == "__main__":
    ScreensApp().run()
class The_AssignmentApp(App):  
    def build(self):  
        return RootWidget()
if __name__ == "__main__":
    The_AssignmentApp().run()

This is the kv file:

#:kivy 1.10.1

<ScreenOne>:

    BoxLayout:
        orientation: "vertical"
        size: root.size
        spacing: 15                
        padding: 200


        Label:
            font_size: 34
            text: "Pasmar"
        Button:
            background_color: 0, 255, 0, .255
            text: "Start Pasmar"
            on_release: root.manager.current = "screen2"

<ScreenTwo>:        

    BoxLayout:
        orientation: "vertical"
        size: root.size
        spacing: 20
        padding: 20


<Manager>:
    id: screen_manager

    screen_one: screen_one
    screen_two: screen_two

    ScreenOne:
        id: screen_one
        name: "screen1"
        manager: screen_manager

    ScreenTwo:
        id: screen_two
        name: "screen2"
        manager: screen_manager
John Anderson
  • 35,991
  • 4
  • 13
  • 36
  • Very confusing. Your first file looks like it will try to start two apps: `ScreensApp` and `Screens2App`. Is that your intention? The second file appears to feed python code to the `Builder`, which normally expects `kv` language. Also, please correct the indentation, so we can tell what is really happening. – John Anderson Jan 02 '19 at 17:16
  • Sorry about the indentation, i corrected it, yes it leads to another file, i also put the other file, you can see it. – DarkHorrorOfThirdEye Jan 02 '19 at 19:28
  • I edited your code a bit more to fix what I believe were a few more indentation errors. Still not sure what you are attempting to do. When I run your code, I see a `Start Pasmar` button. When I click that button, the `ScreenManager` switches to `ScreenTwo`, but that screen is empty, so nothing shows. I also don't understand the attempt to start a second app, and I suspect that you cannot do that. Please explain what you are expecting this code to do. – John Anderson Jan 02 '19 at 22:35
  • I did explain, but ill explain again in case i didn't say it correctly, i want it to run a simple image as a button, in the next page. – DarkHorrorOfThirdEye Jan 04 '19 at 21:33
  • If you are asking how to use an `Image` as a `Button`, see [this](https://stackoverflow.com/questions/33489143/kivy-image-as-button). Then you can add the `ImageButton` to your `ScreenTwo`. – John Anderson Jan 05 '19 at 00:41
  • Yes if you look ive tried that in the first code, it doesnt work, i dont know how to put it on the second page – DarkHorrorOfThirdEye Jan 05 '19 at 06:39
  • You have defined `ImageButton`, but you haven't used it. In your `kv` file, inside the `` rule, add `ImageButton:` and its attendant properties (like `source`). – John Anderson Jan 05 '19 at 15:06
  • Can you tell me how im a newbie to kivy.. – DarkHorrorOfThirdEye Jan 13 '19 at 12:24
  • I put this: : FloatLayout: Image: source:'Card_club.png' size_hint: .2, .2 in screen two, It gives an error – DarkHorrorOfThirdEye Jan 13 '19 at 13:04
  • (the image name is correct) – DarkHorrorOfThirdEye Jan 13 '19 at 13:06
  • I figured it out! its works now but there is a white background appearing at the back of it – DarkHorrorOfThirdEye Jan 13 '19 at 14:00

0 Answers0