Im new to programming and im trying to make a simple program to replace something i copied with a string when its more than 10 characters long, this is the code:
import pyperclip
import tkinter as Tk
while True:
r = Tk()
r.withdraw()
try:
selection = r.selection.get(selection="CLIPBOARD")
except tk.TclError:
selection = None
sleep(0.1)
try:
selection = r.selection.get(selection="CLIPBOARD")
except tk.TclError:
selection = None
r.clipboard_clear()
if len(result) > 10:
pyperclip.copy("aaa")
But its giving me this error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: 'module' object is not callable
>>>
I understand this is probably related to the tkinter module but i dont really know what it is or how to solve it.
You are trying to call the Tk
which is actually the alias for the tkinter
module. What you would want to do in this case is:
r = Tk.Tk()
import pyperclip
import tkinter as Tk
while True:
r = Tk.Tk()
r.withdraw()
try:
selection = r.selection.get(selection="CLIPBOARD")
except tk.TclError:
selection = None
sleep(0.1)
try:
selection = r.selection.get(selection="CLIPBOARD")
except tk.TclError:
selection = None
r.clipboard_clear()
if len(result) > 10:
pyperclip.copy("aaa")
Tk is a module, basically, it's tkinter module only that u called it in another name in your code. This is why you can't do Tk()
. You probably want to do something like:
r = Tk.NameOfClass()
or
from Tkinter import NameOfClass
Replace NameOfClass with the name of the class you want to use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.