mistersenpai
mistersenpai

Reputation: 59

tkinter converted to exe not opening

I was making some simple program using tkinter which allows me to change my computer resolution. It runs fine when directly running it thought the python IDLE, but when I convert it to an EXE using auto-py-to-exe and py-installer, the tkinter window doesn't open up and the command prompt momentarily opens until closing by itself. At first I thought it was my code or modules as my code uses winapi, but I tried it on another tkinter I made but this also fails to open a converted tkinter exe.

import win32api
import win32con
import pywintypes
from tkinter import *

def quit():
    main_window.destroy()

def main():
    global option
    option = StringVar()
    
    main_window.geometry("300x200")
    main_window.title("change resolution")

    selected_label = Label(main_window, textvariable = option, font = 'Arial 15 bold')
    selected_label.grid(column=0, row=0)

    choose_label = Label(main_window, text = "Please choose an option")
    choose_label.grid(column=0, row=1)

    defaultbutton = Button(main_window, text= 'default', command = default)
    defaultbutton.grid(column=0, row=2)
    teamviewerbutton = Button(main_window, text= 'teamviewer', command = teamviewer)
    teamviewerbutton.grid(column=1, row=2)

    quitbutton = Button(main_window, text = 'quit', command = quit)
    quitbutton.grid(column=1, row=0)

    
    

def default():
    option.set("default")
    
    devmode = pywintypes.DEVMODEType()

    devmode.PelsWidth = 3440
    devmode.PelsHeight = 1440

    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT

    win32api.ChangeDisplaySettings(devmode, 0)


def teamviewer():
    option.set("teamviwer")

    devmode = pywintypes.DEVMODEType()

    devmode.PelsWidth = 1920
    devmode.PelsHeight = 1080
    devmode.Scale = 2

    devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT

    win32api.ChangeDisplaySettings(devmode, 0)

main_window = Tk()


main()

Upvotes: 0

Views: 754

Answers (1)

mistersenpai
mistersenpai

Reputation: 59

Thanks for Rahul for the answer, the answer was rather simple, its just been a while since I last used this.

main_window.mainloop()

or

[root tk].mainloop()

This should be put at the bottom of your code, right underneath main().

Upvotes: 1

Related Questions