Skip to content

Instantly share code, notes, and snippets.

@jtuttas
Created January 2, 2021 11:57
Show Gist options
  • Save jtuttas/127cbedd87a012ab32e74df81c356e0d to your computer and use it in GitHub Desktop.
Save jtuttas/127cbedd87a012ab32e74df81c356e0d to your computer and use it in GitHub Desktop.
Python
from tkinter import *
from tkinter.font import Font
import time
import random
import win32com.client
from tkinter import filedialog
rand=-1
slides=0
myPresentation=None
def open_file():
global myPresentation
global slides
file = filedialog.askopenfile(mode="r", filetypes=[('Powerpoint',['.pptx','.ppt'])])
print("Selected:"+file.name)
myPowerpoint = win32com.client.Dispatch('Powerpoint.Application')
myPowerpoint.Activate()
myPresentation = myPowerpoint.Presentations.Open(file.name)
slides = myPresentation.Slides.Count
global e1
e1.delete(0,END)
e1.insert(0,str(slides))
global btn
btn.config(state='normal')
def clicked():
global myPresentation
global rand
orand=rand
for i in range(1,10):
rand=random.randint(1,int(e1.get()))
lbl.configure(text=str(rand))
lbl.update()
time.sleep(0.1)
if (orand!=-1):
myPresentation.Slides(orand).delete()
myPresentation.Slides(rand).select()
n=int(e1.get())-1
e1.delete(0,END)
e1.insert(0,str(n))
if (n==0):
btn.config(state='disabled')
window = Tk()
myFont = Font(family="Gill Sans Ultra Bold", size=20)
myFont2 = Font(family="Gill Sans Ultra Bold", size=92)
window.title("1 aus N")
window.geometry("400x300")
btn = Button(window, text="Next",command=clicked,padx=5,pady=5)
btn.configure(font=myFont)
btn.config(state='disabled')
btnOpen = Button(window, text="Open",command= lambda:open_file())
lbl = Label(window, text="?",padx=5,pady=5)
lbl.configure(font=myFont2)
lble1 = Label(window, text="N:",padx=5,pady=5)
e1 = Entry(window)
e1.insert(0,"0")
btn.place(x=200,y=240, anchor=CENTER)
lbl.place(x=200,y=120,anchor=CENTER)
btnOpen.place(x=350,y=15,anchor=CENTER)
lble1.place(x=10,y=15,anchor=CENTER)
e1.place(x=80,y=15,anchor=CENTER)
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment