-3

When I double click the .pyw file it doesn't run the code and open the GUI. It worked in 2.7 but I don't know.

from tkinter import *
from tkinter import ttk
import os

root = Tk()
root.geometry('%dx%d+0+0' % (180 ,200))
root.title('Title Headder')

def run1():
    #os.startfile("scripts\test.pyw")
    print("Hello")

mainframe = ttk.Frame(root, padding=("6 6 12 12"))
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

#spacers
ttk.Label(root,text='  ')

ttk.Label(mainframe, text=u"Title", anchor='center',font=("NK57 Monospace", 28, "underline")).grid(in_=mainframe,column=0, row=0, columnspan=3, sticky=EW)

#spacers
ttk.Label(root,text='  ').grid(in_=mainframe,column=0, row=2, columnspan=3, sticky=EW)

#buttons

ttk.Button(mainframe,text = "Button", command=run1).grid(column=1, row=3, sticky=N)

ttk.Button(mainframe, text="Button").grid(in_=mainframe,column=0, row=4, columnspan=3, sticky=EW)

ttk.Button(mainframe, text="Button").grid(in_=mainframe,column=0, row=5, columnspan=3, sticky=EW)

#spacers
ttk.Label(root,text='  ').grid(in_=mainframe,column=0, row=6, columnspan=3, sticky=EW)

ttk.Label(mainframe, text=u"Created by TheEvil_potato", anchor='center',font=("NK57 Monospace", 10)).grid(in_=mainframe,column=0, row=7, columnspan=3, sticky=EW)

root.mainloop()

EDIT: I've added the code as I had forgotten. Sorry for that and all answers are appreciated.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
TheEvil_potato
  • 33
  • 1
  • 1
  • 7

1 Answers1

1

I can't reproduce your error, but I have an idea what's causing it.

My guess is that your OS runs .pyw files using py2. You can double check this in your registry (assuming Windows). Check the following key

Computer\HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command

And change its default value to

"C:\Python34\pythonw.exe" "%1" %*

Or wherever your Python3 installation lives. My guess is that, like mine, it currently reads

"C:\Python27\pythonw.exe" "%1" %*

Which launches the script with Python2, throws an immediate ImportError since tkinter is Tkinter on Python2, and exits without further issue.

Adam Smith
  • 52,157
  • 12
  • 73
  • 112