Skip to content

I want something like this need in examples directory #40

@Suletta-Majo

Description

@Suletta-Majo

I was trying to somehow draw heres example program, cube.py, in the right pane (frame?) of the following example program: but confused and retired.
https://github.com/TomSchimansky/CustomTkinter/blob/master/examples/image_example.py
I tried to find something simpler, but in the end I asked AI copilot to write a simple code for me.
Here's a slightly my revised version of it:

import tkinter as tk
from pyopengltk import OpenGLFrame
from OpenGL.GL import *

class App:
    def __init__(self, root):
        self.root = root
        self.root.title("Tkinter with PyOpenGL")

        # Create the left frame (menu)
        self.menu_frame = tk.Frame(self.root, width=200, height=400, bg='lightgrey')
        self.menu_frame.pack(side='left', fill='y')

        # Create the right frame (application area)
        self.app_frame = tk.Frame(self.root, bg='white', width=400, height=400)
        self.app_frame.pack(side='right', fill='both', expand=True)

        # Button 1
        self.button1 = tk.Button(self.menu_frame, text="Button 1", command=self.display_hello_world)
        self.button1.pack(pady=10)

        # Button 2
        self.button2 = tk.Button(self.menu_frame, text="Button 2", command=self.display_triangle)
        self.button2.pack(pady=10)

    def display_hello_world(self):
        # Clear the app frame
        for widget in self.app_frame.winfo_children():
            widget.destroy()

        # Display "Hello World" in the center
        label = tk.Label(self.app_frame, text="Hello World", font=("Helvetica", 24))
        label.place(relx=0.5, rely=0.5, anchor='center')

    def display_triangle(self):
        # Clear the app frame
        for widget in self.app_frame.winfo_children():
            widget.destroy()

        # Create OpenGL frame
        ogl_frame = OpenGLFrame(self.app_frame, width=400, height=400)
        ogl_frame.pack(fill='both', expand=True)
        # AI suggested -> ogl_frame.after(100, ogl_frame.tkRedraw)
        ogl_frame.after(100, ogl_frame.redraw)


        # Define the draw method
        def draw():
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glLoadIdentity()
            glBegin(GL_TRIANGLES)
            glVertex3f(-0.5, -0.5, 0)
            glVertex3f(0.5, -0.5, 0)
            glVertex3f(0, 0.5, 0)
            glEnd()
            glFlush()

        ogl_frame.redraw = draw


if __name__ == "__main__":
    root = tk.Tk()
    app = App(root)
    root.mainloop()

The triangle was not drawn and the error message "There is no attribute tkRisize in OpenGLFrame. Is it "redraw?" appeared. I changed it without understanding it, and the triangle appeared.
I still get the error "base.py line112 in redraw rize NotImplementedError", but I think you can understand what I want to do.

I hope there were better examples More than this AI generated packed into the examples directory.
(I haven't tried the f3d module file because I can't install f3d with pip on termux.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions