Hi All,

i need to convert this Python code to C# .Tried Some online converters nothing Worked out so far.Please Help.

import openpyxl
from PIL import Image, ImageTk
import Tkinter as tk
import subprocess
import time
import os
import RPi.GPIO as IO
import sys
import glob

def Image_dis(img, delay):
    root = tk.Tk()
    root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
    image = Image.open(img)
    copy_of_image = image.copy()
    photo = ImageTk.PhotoImage(image)
    label = tk.Label(root, image = photo)
    label.bind('<Configure>', resize_image)
    root.after(delay*1000,lambda: root.destroy())

def resize_image(event):
    new_width = event.width
    new_height = event.height
    image = copy_of_image.resize((new_width, new_height))
    photo = ImageTk.PhotoImage(image)
    label.config(image = photo)
    label.image = photo

def Video_dis(vid):
    a = subprocess.call(["omxplayer","-b", vid])

path = '/mnt/'

##pid = subprocess.Popen([sys.executable, "resize.py"])
##root = tk.Tk()
##x = root.winfo_screenwidth()
##y = root.winfo_screenheight()
##for img in glob.glob(os.path.join(path,'*.jpg')):
##    im = Image.open(img)
##    im = im.resize((x,y), Image.ANTIALIAS)
##    im.save(img)

for i in range(0,2):

##    pid = subprocess.Popen([sys.executable, "black.py"])
    file1 = openpyxl.load_workbook(path+"MANDFILEBF.xlsx")
    sheet1 = file1.get_sheet_by_name('Sheet1')

    j = sheet1.max_row
    for k1 in range (1,j):

        for k in range (2,j+1):

            if a == k1:
                c1 = sheet1['A'+str(k)].value
                print c1

                if c1.endswith('jpg'):
                    img = path+c1
                    delay = sheet1['B'+str(k)].value
                    Image_dis(img, delay)

                elif c1.endswith('mp4'):
                    vid = path+c1

6 Months
Discussion Span
Last Post by alc6379

You're probably going to have to rewrite this from scratch. There are a lot of Python libraries that don't have direct analogs to C# libraries, so you'll have to figure out on your own what the code does, and how to interpret it as C#.


@alc6379 The code reads a list of file names in an excel (xlsx) file. The image files (.jpg) are displayed in a resizable window and the video files (mp4) are played in an external process with a player named omxplayer. As this thread is 6 months old, I suspect Nazneen_1 has finished rewriting the code by now :)

Votes + Comments
Here's to hope.

I would hope so-- I was just trawling through the Unanswered section.

It's my general opinion that "converting" one language to another is generally a mess, especially when the languages might have different paradigms or philosophies. Plus, even if someone writes a converter that translates different library calls, not just the base language, you're at the whim of that person's opinions as to how the code should be translated.

Votes + Comments
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.