0

I'm using Python 3, and I had a problem.

I made a test project, but it doesn't work.

Here's my code:

import pygame, sys, os
from pygame.locals import *
from tkinter import *

class A(object):
    def Start(self):
        self.root = Tk()

        self.btn1 = Button(self.root, text = '1', command = self.one())
        self.btn1.grid(row = 0, column = 0)

        self.btn2 = Button(self.root, text = '2', command = self.two())
        self.btn2.grid(row = 0, column = 1)

        self.root.mainloop()

    def one(self):
        pygame.quit()

    def two(self):
        sys.exit()

while True:
    a = A()
    a.Start()
    os.execl(sys.executable, os.path.abspath(__file__), *sys.argv)

What's the problem?

Xantium
  • 11,201
  • 10
  • 62
  • 89
Hoseong Jeon
  • 1,240
  • 2
  • 12
  • 20

1 Answers1

1

Oh, I think I found the answer myself.

I had to change self.one() and self.two() to self.one and self.two.

And I had to change some codes to make it.

Here's the answer:

import pygame, sys, os
from pygame.locals import *
from tkinter import *

class A(object):
    def Start(self):
        self.root = Tk()

        self.btn1 = Button(self.root, text = '1', command = self.one)
        self.btn1.grid(row = 0, column = 0)

        self.btn2 = Button(self.root, text = '2', command = self.two)
        self.btn2.grid(row = 0, column = 1)

        self.root.mainloop()

    def one(self):
        self.root.destroy()

    def two(self):
        self.root.destroy()
        pygame.quit()
        sys.exit()

def START():
    a = A()
    a.Start()

while True:
    START()
    os.execl(sys.executable, os.path.abspath(__file__), *sys.argv)
Hoseong Jeon
  • 1,240
  • 2
  • 12
  • 20