mlibre
mlibre

Reputation: 2540

python3.4 tkinter.scrolledtext not callable

I write this simple code:

from tkinter import *
from tkinter import ttk
import tkinter.scrolledtext

root = Tk()
textPad = tkinter.scrolledtext(root)
textPad.pack()
root.mainloop()

But not run. output is:

Traceback (most recent call last):
  File "E:/m/lale/test/test.py", line 6, in <module>
    textPad = tkinter.scrolledtext(root)
TypeError: 'module' object is not callable

Upvotes: 5

Views: 9203

Answers (3)

Federico Ba&#249;
Federico Ba&#249;

Reputation: 7646

Quick Script for using Tkinter / tkinter for Python 2. & Python 3.**

I had a script which had different imports of Python 2.* Tkinter so browsing a but I see that the answer are all scattered. Here a small summary with a safe Script for using both Python versions.

try:
    import Tkinter as tk
    import tkMessageBox as tkm
    import ScrolledText as tkst
    from tkFileDialog import askopenfilename
except ImportError:
    import tkinter as tk
    import tkinter.messagebox as tkm
    import tkinter.scrolledtext as tkst
    from tkinter.filedialog import askopenfilename

List of ModuleNotFoundError Errors (When Running Python 3.)

ModuleNotFoundError: No module named 'Tkinter'
ModuleNotFoundError: No module named 'tkMessageBox'
ModuleNotFoundError: No module named 'ScrolledText'
ModuleNotFoundError: No module named 'tkFileDialog'

Upvotes: 0

iresh jayawardana
iresh jayawardana

Reputation: 1

In python 3.7 following worked for me,

import tkinter as tk
from tkinter import *

from tkinter import scrolledtext
txt = tk.scrolledtext.ScrolledText(window,width=40,height=10)

Upvotes: 0

Terry Jan Reedy
Terry Jan Reedy

Reputation: 19144

You are almost there. You need the ScrolledText class from the scrolledtext module. This works.

import tkinter as tk
from tkinter.scrolledtext import ScrolledText

root = tk.Tk()
textPad = ScrolledText(root)
textPad.pack()
root.mainloop()

Upvotes: 14

Related Questions