Code: Alles auswählen
Import Tkinter as tk
spiel = tk.Tk()
spiel.geometry("1024x768")
spflaeche = tk.Canvas(spiel,bg="white")
spflaeche.pack(expand=True,fill=tk.BOTH,padx=25,pady=30)
spiel.mainloop()
Code: Alles auswählen
Import Tkinter as tk
spiel = tk.Tk()
spiel.geometry("1024x768")
spflaeche = tk.Canvas(spiel,bg="white")
spflaeche.pack(expand=True,fill=tk.BOTH,padx=25,pady=30)
spiel.mainloop()
Code: Alles auswählen
import Tkinter as tk
spiel = tk.Tk()
spiel.geometry("1024x768")
linkeseite = tk.Frame(spiel,bg="tomato",width=100)
linkeseite.pack(side=tk.LEFT,fill=tk.Y)
rechteseite = tk.Frame(spiel,bg="peachpuff")
rechteseite.pack(side=tk.LEFT,fill=tk.BOTH,expand=True)
spflaeche = tk.Canvas(rechteseite,bg="white")
spflaeche.pack(expand=True,fill=tk.BOTH,padx=25,pady=30)
spiel.mainloop()
Code: Alles auswählen
Code: Alles auswählen
import Tkinter as tk
from funktionen import *
#Hauptfenster erzeugen
spiel = tk.Tk()
spiel.geometry("1024x768")
spiel.title("Kai s Battle Game")
#Frame1 erzeugen
fenster1 = tk.Frame(spiel,padx=10,pady=10)
fenster1.config(relief=tk.RAISED)
fenster1.pack()
spiel.mainloo
Code: Alles auswählen
spiel.config(width=1024,height=768,bg="grey")
Code: Alles auswählen
spiel.geometry("1024x768")
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#~~ Skriptname: kais_code_1511_01
import Tkinter as tk
from funktionen import *
#Hauptfenster erzeugen
spiel = tk.Tk()
# #~~ System Bildschirm-Grösse
# OS_SCREEN_WIDTH = spiel.winfo_screenwidth()
# OS_SCREEN_HEIGHT = spiel.winfo_screenheight()
#
# #~~ Konstanten des Haupt-Fensters (Systembezogen)
# MAIN_WIN_WIDTH = OS_SCREEN_WIDTH
# MAIN_WIN_HEIGHT = OS_SCREEN_HEIGHT
# MAIN_WIN_XPOS = 0
# MAIN_WIN_YPOS = 0
#~~ Konstanten des Haupt-Fensters (Nach Vorgabe)
MAIN_WIN_WIDTH = 1024
MAIN_WIN_HEIGHT = 768
MAIN_WIN_XPOS = 0
MAIN_WIN_YPOS = 0
#~~ Geometrie für das Hauptfentser
spiel.geometry("%dx%d+%d+%d" % (MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT, MAIN_WIN_XPOS,
MAIN_WIN_YPOS))
spiel.title("Kai s Battle Game")
#Canvas im Frame Fenster2
spflaeche = tk.Canvas(spiel, bg="white")
erstelle_hexfeldobjekte (spielreihen, ungerade_spalten)
# for x in hexdic.iterkeys() :
#
# spflaeche.create_polygon (hexdic[x][0],fill=hexdic[x][2],outline="black")
spflaeche.pack(side='top', fill='both', expand='yes', padx=25, pady=30)
spiel.mainloop()
Code: Alles auswählen
import Tkinter as tk
from funktionen import *
#Hauptfenster erzeugen
spiel = tk.Tk()
spiel.geometry("1024x768")
spiel.title("Kai s Battle Game")
spiel.config(bg="grey")
#Frame1 erzeugen
fenster1 = tk.Frame(spiel,bg="white",width=500,
height=500,bd=3,relief=tk.SUNKEN)
fenster1.pack(anchor=tk.NW,padx=5,pady=5)
#Scrollbar erzeugen
xleiste = tk.Scrollbar(spiel,orient=tk.HORIZONTAL,width=200)
xleiste.pack(anchor=tk.NW,padx=10)
#Canvas im Hauptfenster
spflaeche = tk.Canvas (fenster1,width=490,height=490)
erstelle_hexfeldobjekte (spielreihen, ungerade_spalten)
for x in hexdic.iterkeys() :
spflaeche.create_polygon (hexdic[x][0],fill=hexdic[x][2],outline="black")
spflaeche.pack()
#Verknuepfung Scrollbar
xleiste.config(command=spflaeche.xview)
spiel.mainloop()
Hier die Spielfläche als nicht geflutet dargestellt:Einen Pfad von einem Feld (i, j) zu einem Feld (n, m)
kann man mit Hilfe eines 'Flood Fill' Algorithmus
bestimmen (rein informell):
1. Markieriere alle Felder als unbesucht
2. setze Feld(n, m) auf 0
3. setze die 6er-Nachbarn von Feld (n, m) auf 1
4. setze deren unbesuchte Nachbarn auf 2
5. deren unbesuchte auf 3
usw.
(Hindernisse werden nicht besucht.)
Hier das Spielfeld auf zwei Ebenen geflutet. Das Zielfeld ist auf Koordinate 3,3:Code: Alles auswählen
Spielfläche Geometrie: 7x8 x: 0 1 2 3 4 5 6 y: ------------------------------------- 0 | -1 -1 -1 -1 | | -1 -1 -1 | 1 | -1 -1 -1 -1 | | -1 -1 -1 | 2 | -1 -1 -1 -1 | | -1 -1 -1 | 3 | -1 -1 -1 -1 | | -1 -1 -1 | 4 | -1 -1 -1 -1 | | -1 -1 -1 | 5 | -1 -1 -1 -1 | | -1 -1 -1 | 6 | -1 -1 -1 -1 | | -1 -1 -1 | 7 | -1 -1 -1 -1 | | -1 -1 -1 | -------------------------------------
Hier das Spielfeld voll geflutet. Das Zielfeld ist immer noch auf Koordinate 3,3:Code: Alles auswählen
Spielfläche Geometrie: 7x8 x: 0 1 2 3 4 5 6 y: ------------------------------------- 0 | -1 -1 -1 -1 | | -1 -1 -1 | 1 | -1 -1 -1 -1 | | -1 2 -1 | 2 | -1 2 2 -1 | | 2 1 2 | 3 | -1 1 1 -1 | | 2 0 2 | 4 | -1 1 1 -1 | | 2 1 2 | 5 | -1 2 2 -1 | | -1 2 -1 | 6 | -1 -1 -1 -1 | | -1 -1 -1 | 7 | -1 -1 -1 -1 | | -1 -1 -1 | -------------------------------------
Hier das Spielfeld voll geflutet. Das Zielfeld ist in der untere rechten Ecke auf Koordinate 6,7:Code: Alles auswählen
Spielfläche Geometrie: 7x8 x: 0 1 2 3 4 5 6 y: ------------------------------------- 0 | 5 4 4 5 | | 4 3 4 | 1 | 4 3 3 4 | | 3 2 3 | 2 | 3 2 2 3 | | 2 1 2 | 3 | 3 1 1 3 | | 2 0 2 | 4 | 3 1 1 3 | | 2 1 2 | 5 | 3 2 2 3 | | 3 2 3 | 6 | 4 3 3 4 | | 4 3 4 | 7 | 5 4 4 5 | | 5 4 5 | -------------------------------------
Das Spielfeld enthält noch keine Hindernisse!Code: Alles auswählen
Spielfläche Geometrie: 7x8 x: 0 1 2 3 4 5 6 y: ------------------------------------- 0 | 10 9 8 7 | | 9 8 7 | 1 | 9 8 7 6 | | 8 7 6 | 2 | 8 7 6 5 | | 7 6 5 | 3 | 7 6 5 4 | | 6 5 4 | 4 | 6 5 4 3 | | 5 4 3 | 5 | 6 4 3 2 | | 5 3 2 | 6 | 6 4 2 1 | | 5 3 1 | 7 | 6 4 2 0 | | 5 3 1 | -------------------------------------
derkai hat geschrieben:jetzt bleibt noch das Problem der Scrollbar :
Das rechte Ende des Balkens ist irgendwo im Nirvana.
Was kann man denn dagegen tun ?
Code: Alles auswählen
import Tkinter as tk
spiel = tk.Tk()
spiel.geometry("1024x768")
linkeseite = tk.Frame(spiel,bg="tomato",width=100)
linkeseite.pack(side=tk.LEFT,fill=tk.Y)
rechteseite = tk.Frame(spiel,bg="peachpuff",bd=3,relief=tk.SUNKEN)
rechteseite.pack(side=tk.LEFT,fill=tk.BOTH,expand=True)
spflaeche = tk.Canvas(rechteseite,bg="white")
spflaeche.pack(expand=True,fill=tk.BOTH,padx=25,pady=30)
schieber = tk.Scrollbar(rechteseite,orient=tk.HORIZONTAL)
schieber.pack(fill=tk.X)
spiel.mainloop()
Haargenau...Ich habe dich schon richtig verstanden, dass dies die Basis ist für eine Pfadsuche von einem Startfeld zu einem Zielfeld indem vom Startfeld beginnend immer das Nachbarfeld mit der nächst tieferen Flut-Nummer gesucht wird bis das Zielfeld mit der Flut-Nummer '0' gefunden wird?
Code: Alles auswählen
import Tkinter as tk
from funktionen import *
#Hauptfenster erzeugen
spiel = tk.Tk()
spiel.geometry("1024x768")
spiel.title("Kai s Battle Game")
spiel.config(bg="grey")
#Frame1 erzeugen
fenster1 = tk.Frame(spiel,bg="white",width=500,
height=500,bd=2,relief=tk.SUNKEN)
fenster1.pack(anchor=tk.NW,padx=2,pady=2)
#Scrollbar erzeugen
xleiste = tk.Scrollbar(fenster1,orient=tk.HORIZONTAL)
yleiste = tk.Scrollbar(fenster1,orient=tk.VERTICAL)
xleiste.pack(side=tk.BOTTOM,pady=2,fill=tk.X)
yleiste.pack(side=tk.RIGHT,pady=2,fill=tk.Y)
#Canvas im Hauptfenster
spflaeche = tk.Canvas (fenster1,width=495,height=495)
erstelle_hexfeldobjekte (spielreihen, ungerade_spalten)
for x in hexdic.iterkeys() :
spflaeche.create_polygon (hexdic[x][0],fill=hexdic[x][2],outline="black")
spflaeche.pack(fill=tk.X)
#Verknuepfung Scrollbar
xleiste.config(command=spflaeche.xview)
yleiste.config(command=spflaeche.yview)
#Frame2 erzeugen -> Miniaturansicht
fenster2 = tk.Frame(spiel,bg="white",width=200,height=200,
bd=2,relief=tk.SUNKEN)
fenster2.pack(side=tk.RIGHT,expand=1)
spiel.mainloop()
Klar, kannst du. Aber einfacher wird es dadurch m.E. nicht.derkai hat geschrieben:sagt mal, kann ich denn nicht auch grid nehmen ?
Code: Alles auswählen
import Tkinter as tk
class Scroller(object):
def __init__(self, root):
self.root = root
self.frame = tk.Frame(self.root)
self.canvas = tk.Canvas(self.frame, width=100, height=100, bg='white')
xscroll = tk.Scrollbar(self.root, orient='horizontal')
self.canvas.config(xscrollcommand=xscroll.set)
xscroll.config(command=self.canvas.xview)
yscroll = tk.Scrollbar(self.root, orient='vertical')
self.canvas.config(yscrollcommand=yscroll.set)
yscroll.config(command=self.canvas.yview)
w = 999
self.canvas.config(scrollregion=(0, 0, w, w))
self.canvas.pack(side=tk.LEFT, expand=1, fill=tk.BOTH)
self.frame.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
yscroll.grid(row=0, column=1, sticky=tk.N+tk.S)
xscroll.grid(row=1, column=0, sticky=tk.E+tk.W)
self.root.grid_columnconfigure(0, weight=1)
self.root.grid_rowconfigure(0, weight=1)
p0 = (0, 0)
p1 = (w >> 1, w - 1)
p2 = (w - 1, 0)
self.canvas.create_line(p0, p1)
self.canvas.create_line(p1, p2)
if __name__ == '__main__':
root = tk.Tk()
Scroller(root)
root.mainloop()
Code: Alles auswählen
fenster1.pack(side=tk.LEFT, ...