1

For example, the use case would be the user downloading a csv file that their friend made with another copy of my program, finding it from my program using open_file_dialog and then allowing the program to use it as a list variable to create the output.

I currently have the following but when I print data it is a None object

def openFile(self, sender, data):
    open_file_dialog(callback= csvUser, extensions='.csv')
    #ensures only csvs are searched

def csvUser(self, sender, data):
    print(data)

I would like to do the following but it doesn't seem possible:

listObject = open_file_dialog(extensions='.csv')
for i in listObject:
   print(i)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • As far as I can tell it looks like you could write your own "wrapper function" that used the `open_file_dialog()` internally and provided it with the callback function it requires. The callback function could then use the arguments that it will be passed to open the csv file, read its contents, and store it into a list. The wrapper function could the return this list. – martineau Mar 20 '21 at 19:16

1 Answers1

5

Creating a minimal dearpygui with your pieces:

from dearpygui.core import *
from dearpygui.simple import *
import os

class MyClass:

    def openFile(self, sender, data):
        open_file_dialog(callback= self.csvUser, extensions='.csv')
        #ensures only csvs are searched

    def csvUser(self, sender, data):
        filename = os.sep.join(data)
        for i in open(filename,"rt"):
            print (i)

myhandler = MyClass()

with window("Open a csv"):
    add_button("Open",callback=myhandler.openFile)

start_dearpygui()
RufusVS
  • 4,008
  • 3
  • 29
  • 40