Skip to content

Commit

Permalink
Add tkinter.py to examples (#1437)
Browse files Browse the repository at this point in the history
* Add tkinter.py to examples

Example for tkinter and customtkinter gui building

* Update and rename tkinter.py to minimal_tkinter.py

* Update minimal_tkinter.py

Changed title to Minimal tkinter interface
  • Loading branch information
JPLost authored May 31, 2024
1 parent 97978bc commit 789fb56
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/libf3d/python/tkinter/minimal_tkinter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tkinter as tk # Works also on CustomTKinter

import f3d
from pyopengltk import OpenGLFrame

class Frame(OpenGLFrame):
# !!!OpenGlFrame requires adding own code to initgl and redraw!!!
# !!!This solution only renders the F3D viewer, as it uses EXTERNAL, so controls need to be defined!!!
def __init__(self):
super().__init__()
self.engine = None

# Initialize F3D
def initgl(self):
self.engine = f3d.Engine(f3d.Window.Type.EXTERNAL)
self.engine.loader.load_geometry(
f3d.Mesh(
points=[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0],
face_sides=[3],
face_indices=[0, 1, 2],
)
)

def redraw(self):
self.engine.window.render()

if __name__ == "__main__":
# Create main window and define size, position and title
root = tk.Tk()
root.geometry('640x480+100+100')
root.title('Minimal tkinter interface')
# Create OpenGL instance
F3D = Frame()
F3D.pack(fill=tk.BOTH, expand=tk.YES)

# Run TKinter mainloop
root.mainloop()

0 comments on commit 789fb56

Please sign in to comment.