Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 import Tkinter
#1
my code:
#!/usr/bin/env python
import Tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.grid()
        self.createWidgets()

    def createWidgets(self):
        self.quitButton = tk.Button(self, text='Quit',
            command=self.quit)
        self.quitButton.grid()

app = Application()
app.master.title('Sample application')
app.mainloop()
error messages
Error:
"K:\PycharmProjects\Physics Grading\venv\Scripts\python.exe" "K:/PycharmProjects/Physics Grading/Tkinter.py" Traceback (most recent call last): File "K:/PycharmProjects/Physics Grading/Tkinter.py", line 2, in <module> import Tkinter as tk File "K:\PycharmProjects\Physics Grading\Tkinter.py", line 4, in <module> class Application(tk.Frame): AttributeError: partially initialized module 'Tkinter' has no attribute 'Frame' (most likely due to a circular import) Process finished with exit code 1
Don't understand
Huh
buran wrote Yesterday, 06:17 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
orestgogosha, what version of python are you using?

"Tkinter" is from post python 3x

To have the code work simply change the "Tkinter" in your import line to "tkinter" (proper for python versions 3x).
Keep in mind that when you run this code it will not close correctly when you click the Exit button because there is no definition statement in the code. I'll let you code that in for learning purposes.
#!/usr/bin/env python

#Changed Tkinter to tkinter for python versions 3x.
import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.grid()
        self.createWidgets()

    def createWidgets(self):
        self.quitButton = tk.Button(self, text='Quit',
            command=self.quit)
        self.quitButton.grid()

app = Application()
app.master.title('Sample application')
app.mainloop()
"Often stumped... But never defeated."
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  IDLE can't import Tkinter turtleman 3 340 Jan-17-2020, 05:34 PM
Last Post: turtleman
  [Tkinter] Top Level Window - from tkinter import * francisco_neves2020 6 758 Apr-23-2019, 09:27 PM
Last Post: francisco_neves2020
  tkinter import problems on mac Lux 2 2,814 Jul-30-2017, 07:14 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)