Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys how is possible in pyTLK create a tablewidget? i try in this mode but crash the application and not appear a table
    from fltk import *
import sys

window = None

class MyTable(Fl_Table):
    def __init__(self, x, y, w, h, title):
        Fl_Table.__init__(self, x, y, w, h, title)
        self.rows = 10
        self.cols = 1

    def draw_cell(self, context, row, col, x, y, w, h):
        context.draw_text(x + 2, y, w - 4, h, f"Item {row + 1}", FL_ALIGN_LEFT)

def cell_callback(ptr, widget):
    selected_item = table.callback_row()
    print("Selected item:", selected_item)

def exitcb(ptr, widget):
    sys.exit(0)

window = Fl_Window(10, 100, 1440, 250, "Terminal")

table = MyTable(10, 31, 480, 210, "Table")
table.callback(cell_callback)

b1 = Fl_Button(1345, 4, 80, 21, "&Connetti")
b1.callback(cell_callback, window)

window.end()

window.show()
Fl.run()


What I have tried:

i try to remove a class table and work
Posted
Updated 10-Aug-23 5:52am
Comments
Richard MacCutchan 10-Aug-23 8:36am    
There is nothing obvious in the code (assuming you have verified it with the documentation). So you need to use the debugger to find out exactly where it crashes and why.

1 solution

I have just run your code and it flashed the window and immediately terminated. So I removed the following two lines:
Python
table = MyTable(10, 31, 480, 210, "Table")
table.callback(cell_callback)

and the window shows up as it should - but obviously without the table. So you need to check your code to see why the creation of the table causes it to fail.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900