Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Learning curve to use LLMs (Large Langage Models, like ChatGPT), your new Programming 102 #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stonebig opened this issue May 2, 2023 · 3 comments

Comments

@stonebig
Copy link
Contributor

stonebig commented May 2, 2023

There is no doubts that the "art of programming" is going to evolve into "the art of making the machine programming", as:

  • the hard programming on a blank page is going to diminish,
  • stating and solving the problems will get comparatively bigger.

Let see on one problem:

To summarize :

  • day1: it's a "live" + "interactive" replacement to "google search + stackoverflow",
  • the "skill" of using LLMS is something you must learn by following some tutorial + doing,
  • ongoing LLMs refinements (chatGPT4 with codeInterpreter), may furtherimprove the "result"/"time of iterations",
  • the "Simple Programming Army" of users in a Company shall be nourrished, as it will be more and more how work will be done.
@stonebig
Copy link
Contributor Author

stonebig commented May 2, 2023

detail of the Chat with "free" included Edge assistant

Me : can you write a python GUI program with tcl/tk that displays two lists of strings in two separate table, and we can drag & drop a string from one table to the other ?

Edge : Yes, I can help you with that. Here’s a sample Python GUI program that uses the Tkinter library to display two lists of strings in two separate tables and allows you to drag and drop a string from one table to the other:

import tkinter as tk from tkinter import ttk

class DragDropTable(tk.Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.initUI()

def initUI(self):
    self.master.title("Drag and Drop Table")

    # Create two tables
    self.table1 = ttk.Treeview(self.master)
    self.table1.heading("#0", text="Table 1")
    self.table1.pack(side=tk.LEFT)

    self.table2 = ttk.Treeview(self.master)
    self.table2.heading("#0", text="Table 2")
    self.table2.pack(side=tk.RIGHT)

    # Add some sample data to the tables
    for i in range(10):
        self.table1.insert("", "end", text=f"Item {i}")

    for i in range(5):
        self.table2.insert("", "end", text=f"Item {i}")

    # Allow drag and drop between the tables
    self.table1.bind("<Button-1>", self.on_button_press)
    self.table2.bind("<Button-1>", self.on_button_press)
    self.table1.bind("<B1-Motion>", self.on_motion)
    self.table2.bind("<B1-Motion>", self.on_motion)

def on_button_press(self, event):
    widget = event.widget
    item = widget.identify_row(event.y)
    widget.selection_set(item)

def on_motion(self, event):
    widget = event.widget
    item = widget.selection()[0]
    x, y = widget.winfo_pointerxy()
    x -= widget.winfo_rootx()
    y -= widget.winfo_rooty()
    widget.coords(item, x, y)

def main():
root = tk.Tk()
app = DragDropTable(master=root)
app.mainloop()

if name == 'main':
main()

Edge : This program uses the ttk.Treeview widget to create two tables and adds some sample data to them. It also allows you to drag and drop items between the tables by binding the and events. You can modify this program to display your own data and customize it as per your requirements. Let me know if you have any questions.

Me : if I try it, there is an error ttributeError: 'Treeview' object has no attribute 'coords'

Edge: I’m sorry to hear that. The error message you’re seeing (AttributeError: 'Treeview' object has no attribute 'coords') indicates that the coords() method is not available for the Treeview widget. This is because the coords() method is only available for canvas items, not for treeview items.
To fix this error, you can replace the coords() method with the move() method, which is available for both canvas items and treeview items. Here’s the updated code:

import tkinter as tk from tkinter import ttk

class DragDropTable(tk.Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.initUI()

def initUI(self):
    self.master.title("Drag and Drop Table")

    # Create two tables
    self.table1 = ttk.Treeview(self.master)
    self.table1.heading("#0", text="Table 1")
    self.table1.pack(side=tk.LEFT)

    self.table2 = ttk.Treeview(self.master)
    self.table2.heading("#0", text="Table 2")
    self.table2.pack(side=tk.RIGHT)

    # Add some sample data to the tables
    for i in range(10):
        self.table1.insert("", "end", text=f"Item {i}")

    for i in range(5):
        self.table2.insert("", "end", text=f"Item {i}")

    # Allow drag and drop between the tables
    self.table1.bind("<Button-1>", self.on_button_press)
    self.table2.bind("<Button-1>", self.on_button_press)
    self.table1.bind("<B1-Motion>", self.on_motion)
    self.table2.bind("<B1-Motion>", self.on_motion)

def on_button_press(self, event):
    widget = event.widget
    item = widget.identify_row(event.y)
    widget.selection_set(item)

def on_motion(self, event):
    widget = event.widget
    item = widget.selection()[0]
    x, y = widget.winfo_pointerxy()
    x -= widget.winfo_rootx()
    y -= widget.winfo_rooty()
    
    # Replace coords() with move()
    widget.move(item, x, y)

def main():
root = tk.Tk()
app = DragDropTable(master=root)
app.mainloop()

if name == 'main':
main()

Edge : This should fix the error and allow you to drag and drop items between the tables. Let me know if you have any other questions.

Me: whe I tryt to move Item9 from Table1 to table2, I get an error: self.tk.call(self._w, "move", item, parent, index) _tkinter.TclError: Item 43 not found

Edge: I’m sorry to hear that you’re still having issues. The error message you’re seeing (_tkinter.TclError: Item 43 not found) indicates that the item you’re trying to move (Item 9) is not found in the table.
This error can occur if the item you’re trying to move has already been moved or deleted from the table. To fix this error, you can add a check to make sure that the item exists in the table before moving it. Here’s the updated code:

import tkinter as tk from tkinter import ttk

class DragDropTable(tk.Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.initUI()

def initUI(self):
    self.master.title("Drag and Drop Table")

    # Create two tables
    self.table1 = ttk.Treeview(self.master)
    self.table1.heading("#0", text="Table 1")
    self.table1.pack(side=tk.LEFT)

    self.table2 = ttk.Treeview(self.master)
    self.table2.heading("#0", text="Table 2")
    self.table2.pack(side=tk.RIGHT)

    # Add some sample data to the tables
    for i in range(10):
        self.table1.insert("", "end", text=f"Item {i}")

    for i in range(5):
        self.table2.insert("", "end", text=f"Item {i}")

    # Allow drag and drop between the tables
    self.table1.bind("<Button-1>", self.on_button_press)
    self.table2.bind("<Button-1>", self.on_button_press)
    self.table1.bind("<B1-Motion>", self.on_motion)
    self.table2.bind("<B1-Motion>", self.on_motion)

def on_button_press(self, event):
    widget = event.widget
    item = widget.identify_row(event.y)
    
    # Check if item exists in the table
    if item:
        widget.selection_set(item)

def on_motion(self, event):
    widget = event.widget
    item = widget.selection()[0]
    
    # Check if item exists in the table
    if item:
        x, y = widget.winfo_pointerxy()
        x -= widget.winfo_rootx()
        y -= widget.winfo_rooty()
        
        # Use parent() method to get the parent of the item
        parent = widget.parent(item)
        
        # Use index() method to get the index of the item
        index = widget.index(item)
        
        # Move the item to the new position
        widget.move(item, "", index)
        
        # Insert the item into the new table
        if parent == "":
            new_parent = widget2.insert("", "end", text=widget.item(item)["text"])
        else:
            new_parent = widget2.insert(parent, "end", text=widget.item(item)["text"])
        
        # Delete the item from the old table
        widget.delete(item)

def main():
root = tk.Tk()
app = DragDropTable(master=root)
app.mainloop()

if name == 'main':
main()

This should fix the error and allow you to drag and drop items between the tables. Let me know if you have any other questions.

Me: now the error is, for the same action: new_parent = widget2.insert("", "end", text=widget.item(item)["text"]) ^^^^^^^ NameError: name 'widget2' is not defined

Edge : I’m sorry to hear that you’re still having issues. The error message you’re seeing (NameError: name 'widget2' is not defined) indicates that the widget2 variable is not defined in the code.
This error can occur if you forgot to define the widget2 variable or if you misspelled the variable name. To fix this error, you can define the widget2 variable and make sure that it matches the name of the second table widget. Here’s the updated code:

import tkinter as tk from tkinter import ttk

class DragDropTable(tk.Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.initUI()

def initUI(self):
    self.master.title("Drag and Drop Table")

    # Create two tables
    self.table1 = ttk.Treeview(self.master)
    self.table1.heading("#0", text="Table 1")
    self.table1.pack(side=tk.LEFT)

    self.table2 = ttk.Treeview(self.master)
    self.table2.heading("#0", text="Table 2")
    self.table2.pack(side=tk.RIGHT)

    # Add some sample data to the tables
    for i in range(10):
        self.table1.insert("", "end", text=f"Item {i}")

    for i in range(5):
        self.table2.insert("", "end", text=f"Item {i}")

    # Allow drag and drop between the tables
    self.table1.bind("<Button-1>", self.on_button_press)
    self.table2.bind("<Button-1>", self.on_button_press)
    self.table1.bind("<B1-Motion>", self.on_motion)
    self.table2.bind("<B1-Motion>", self.on_motion)

def on_button_press(self, event):
    widget = event.widget
    item = widget.identify_row(event.y)
    
    # Check if item exists in the table
    if item:
        widget.selection_set(item)

def on_motion(self, event):
    widget = event.widget
    item = widget.selection()[0]
    
    # Check if item exists in the table
    if item:
        x, y = widget.winfo_pointerxy()
        x -= widget.winfo_rootx()
        y -= widget.winfo_rooty()
        
        # Use parent() method to get the parent of the item
        parent = widget.parent(item)
        
        # Use index() method to get the index of the item
        index = widget.index(item)
        
        # Move the item to the new position
        widget.move(item, "", index)
        
        # Insert the item into the new table
        if parent == "":
            new_parent = self.table2.insert("", "end", text=widget.item(item)["text"])
        else:
            new_parent = self.table2.insert(parent, "end", text=widget.item(item)["text"])
        
        # Delete the item from the old table
        widget.delete(item)

def main():
root = tk.Tk()
app = DragDropTable(master=root)
app.mainloop()

if name == 'main':
main()

This should fix the error and allow you to drag and drop items between the tables. Let me know if you have any other questions.

Me : when I click on any element on the table1 list, I have this error : File "xxxxxxxxxxxxxxxxxxx/edge-tcl_v04.py", line 45, in on_motion item = widget.selection()[0] ~~~~~~~~~~~~~~~~~~^^^ IndexError: tuple index out of range

Edge : I’m sorry to hear that you’re still having issues. The error message you’re seeing (IndexError: tuple index out of range) indicates that the selection() method is returning an empty tuple.
This error can occur if you’re trying to access an element of an empty tuple or if the selection has not been set in the table. To fix this error, you can add a check to make sure that the selection is not empty before accessing its elements. Here’s the updated code:

import tkinter as tk from tkinter import ttk

class DragDropTable(tk.Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.initUI()

def initUI(self):
    self.master.title("Drag and Drop Table")

    # Create two tables
    self.table1 = ttk.Treeview(self.master)
    self.table1.heading("#0", text="Table 1")
    self.table1.pack(side=tk.LEFT)

    self.table2 = ttk.Treeview(self.master)
    self.table2.heading("#0", text="Table 2")
    self.table2.pack(side=tk.RIGHT)

    # Add some sample data to the tables
    for i in range(10):
        self.table1.insert("", "end", text=f"Item {i}")

    for i in range(5):
        self.table2.insert("", "end", text=f"Item {i}")

    # Allow drag and drop between the tables
    self.table1.bind("<Button-1>", self.on_button_press)
    self.table2.bind("<Button-1>", self.on_button_press)
    self.table1.bind("<B1-Motion>", self.on_motion)
    self.table2.bind("<B1-Motion>", self.on_motion)

def on_button_press(self, event):
    widget = event.widget
    item = widget.identify_row(event.y)
    
    # Check if item exists in the table
    if item:
        widget.selection_set(item)

def on_motion(self, event):
    widget = event.widget
    
    # Check if selection is not empty
    if widget.selection():
        item = widget.selection()[0]
        
        # Use parent() method to get the parent of the item
        parent = widget.parent(item)
        
        # Use index() method to get the index of the item
        index = widget.index(item)
        
        # Move the item to the new position
        widget.move(item, "", index)
        
        # Insert the item into the new table
        if parent == "":
            new_parent = self.table2.insert("", "end", text=widget.item(item)["text"])
        else:
            new_parent = self.table2.insert(parent, "end", text=widget.item(item)["text"])
        
        # Delete the item from the old table
        widget.delete(item)

def main():
root = tk.Tk()
app = DragDropTable(master=root)
app.mainloop()

if name == 'main':
main()

This should fix the error and allow you to drag and drop items between the tables. Let me know if you have any other questions.

Me: now, it works when I want to move elements from table1 to table2, but notihng happens if I want to move items from table2 to table1. can we have also this functionality ?

Edge:
Yes, you can add the functionality to move items from table2 to table1. To do this, you need to add a similar check in the on_motion() method to determine which table the item is being dragged from. Here’s the updated code:

import tkinter as tk
from tkinter import ttk

class DragDropTable(tk.Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.initUI()

def initUI(self):
    self.master.title("Drag and Drop Table")

    # Create two tables
    self.table1 = ttk.Treeview(self.master)
    self.table1.heading("#0", text="Table 1")
    self.table1.pack(side=tk.LEFT)

    self.table2 = ttk.Treeview(self.master)
    self.table2.heading("#0", text="Table 2")
    self.table2.pack(side=tk.RIGHT)

    # Add some sample data to the tables
    for i in range(10):
        self.table1.insert("", "end", text=f"Item {i}")

    for i in range(5):
        self.table2.insert("", "end", text=f"Item {i}")

    # Allow drag and drop between the tables
    self.table1.bind("<Button-1>", self.on_button_press)
    self.table2.bind("<Button-1>", self.on_button_press)
    self.table1.bind("<B1-Motion>", self.on_motion)
    self.table2.bind("<B1-Motion>", self.on_motion)

def on_button_press(self, event):
    widget = event.widget
    item = widget.identify_row(event.y)
    
    # Check if item exists in the table
    if item:
        widget.selection_set(item)

def on_motion(self, event):
    widget = event.widget
    
    # Check if selection is not empty
    if widget.selection():
        item = widget.selection()[0]
        
        # Use parent() method to get the parent of the item
        parent = widget.parent(item)
        
        # Use index() method to get the index of the item
        index = widget.index(item)
        
        # Move the item to the new position
        widget.move(item, "", index)
        
        # Insert the item into the new table
        if parent == "":
            if widget == self.table1:
                new_parent = self.table2.insert("", "end", text=widget.item(item)["text"])
            else:
                new_parent = self.table1.insert("", "end", text=widget.item(item)["text"])
        else:
            if widget == self.table1:
                new_parent = self.table2.insert(parent, "end", text=widget.item(item)["text"])
            else:
                new_parent = self.table1.insert(parent, "end", text=widget.item(item)["text"])
        
        # Delete the item from the old table
        widget.delete(item)

def main():
root = tk.Tk()
app = DragDropTable(master=root)
app.mainloop()

if name == 'main':
main()

Edge: This should allow you to drag and drop items between both tables. Let me know if you have any other questions.

Me : it works, I'm impressed.

@stonebig
Copy link
Contributor Author

stonebig commented May 2, 2023

image

@stonebig stonebig changed the title Learning curve to use LLMs (Large Langage Models, like ChatGPT) is your new Programming 102 Learning curve to use LLMs (Large Langage Models, like ChatGPT), your new Programming 102 May 2, 2023
@stonebig
Copy link
Contributor Author

stonebig commented May 8, 2023

Next step trying to make it work on a weak PC:
https://twitter.com/jefrankle/status/1654495480473169922
image

if it can run on a iphone at 1 word every 7 seconds, it may work on a PC.
... your next Laptop shall better be with a neural engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant