#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright © 2024 Simon Forman # # This file is part of game # # game is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # game is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with game. If not see . # from tkinter import * import data, stars class App: ''' A canvas with scrolling support. ''' def __init__(self, master=None, *canvas_args, **canvas_kw): frame = self.frame = Frame(root, bg='green') frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) frame.pack(expand=True, fill=BOTH) C = self.canvas = Canvas(frame, *canvas_args, **canvas_kw) scrollY = self.scrollY = Scrollbar( frame, orient=VERTICAL, command=C.yview, ) C['yscrollcommand'] = scrollY.set scrollX = self.scrollX = Scrollbar( frame, orient=HORIZONTAL, command=C.xview, ) C['xscrollcommand'] = scrollX.set C.grid(row=0, column=0, sticky=N+S+E+W) scrollY.grid(row=0, column=1, sticky=N+S) scrollX.grid(row=1, column=0, sticky=E+W) C.bind("", self.handle_canvas_resize) def handle_canvas_resize(self, event): print(event) data.open_db() root = Tk() app = App(root, bg='black', scrollregion=(0, 0, stars.WIDTH, stars.HEIGHT)) for x, y, radius in stars.iter_stars(data.conn): star_id = app.canvas.create_oval( x - radius, y - radius, x + radius, y + radius, fill='yellow', outline='yellow', activefill='#550', activeoutline='orange', activewidth=3, ) app.canvas.tag_bind(star_id, '', (lambda event, sid=star_id, x=x, y=y: root.title(f'{x}, {y}'))) app.frame.mainloop() data.close_db()