Reputation: 11
My English Crash Course program requires that the user navigate to the next/previous first and last record until the end of the table by clicking buttons that say move next/previous last/first. this code always bring the first
and the next row every time i press the button what should I change in this code to enable this?
import kivy
from kivy.config import Config
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '500')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.image import Image
import sqlite3
from kivy.uix.screenmanager import ScreenManager,Screen
class Firstwindow(Screen):
pass
class Secondwindow(Screen):
pass
class Thirdwindow(Screen):
def getSingleRows(self):
connection = sqlite3.connect('book.db')
cursor = connection.cursor()
print("Connected to database")
sqlite_select_query = """SELECT question FROM advanced"""
cursor.execute(sqlite_select_query)
print("Fetching single row")
record = cursor.fetchone()
self.ids.q.text = str(record)
print(record)
print("Fetching next row")
record = cursor.fetchone()
print(record)
cursor.close()
class WindowManager(ScreenManager):
def screen_manager_method(self):
pass
class CrashCourse(App):
def build(self):
Builder.load_file("crashcourse.kv")
return WindowManager()
if __name__ == '__main__':
CrashCourse().run()`
` crashcourse.kv
self.ids.q.text = str(record)
self.ids.q.text = str(record)
<WindowManager>:
Firstwindow:
Secondwindow:
Thirdwindow:
<Firstwindow>:
``canvas:
Rectangle:
source:"down.jpg"
size: self.size
name: "home_screen"
id: home_screen
Button:
id: b1
text: 'Beginner'
color:"purple"
pos:200,300
size_hint:(0.2,0.1)
on_release:
app.root.current="game_screen"
Button:
id: b2
text:" Inermediate"
color:"purple"
pos:200,230
size_hint:(0.2,0.1)
Button:
id: b3
text:"Advanced"
color:"purple"
pos:200,160
size_hint:(0.2,0.1)
on_release:
app.root.current="menu_screen"
<Secondwindow>:
name: "menu_screen"
id: menu_screen
Label:
text:"this is screen two"
<Thirdwindow>:
name: "game_screen"
id: game_screen
GridLayout
cols:2
Label:
text:"first checkbox"
CheckBox:
group:"mygroup"
on_active: root.checkbox_click(self,self.active,"first checkbox")
Label:
text:"second radio button"
CheckBox:
group:"mygroup"
on_active: root.checkbox_click(self,self.active,"second radio button")
Label:
text:"third radio button"
CheckBox:
group:"mygroup"
on_active: root.checkbox_click(self,self.active,"third radio button")
Button:
text:"Move Next"
on_press: root.getSingleRows()`
Upvotes: 0
Views: 9