from Tkinter import *
root = Tk()
root.title("Whois Tool")
text = Text()
text1 = Text()
text1.config(width=15, height=1)
text1.pack()
def button1():
text.insert(INSERT, text1.get("1.0", END))
b = Button(root, text="Enter", width=10, height=2, command=button1)
b.pack()
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
text.config(width=60, height=15)
text.pack(side=LEFT, fill=Y)
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)
root.mainloop()
上面的脚本工作正常,没有任何异常错误,但是如果我修改导入样式:将Tkinter导入为Tk,它将抱怨参数'LEFT,RIGHT,Y',而我不得不将它们变成字符串形式的小写字母,如下脚本所示,为什么就是它?
import Tkinter as tk
root = tk.Tk()
root.title("Whois Tool")
text = tk.Text()
text1 = tk.Text()
text1.config(width=15, height=1)
text1.pack()
def button1():
text.insert('insert', text1.get("1.0", 'end'))
# text.insert(END, text1)
b = tk.Button(root, text="Enter", width=10, height=2, command=button1)
b.pack()
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side='right', fill='y')
text.config(width=60, height=15)
text.pack(side='left', fill='y')
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)
root.mainloop()
使用“将Tkinter导入为Tk”时,必须使用对象Tk调用Tkinter的所有方法和属性。因此,您必须使用Tk.LEFT,Tk.RIGHT来代替“ left”,“ right” ...
在第一个示例中,您使用了“ scrollbar = Scrollbar(root)”,但是在第二个示例中,您编写了“ scrollbar = tk.Scrollbar(root)”
在第二个示例中,已使用对象Tk调用了Tkinter中的所有内容。有关Python模块的更多信息,请访问此处:http : //www.tutorialspoint.com/python/python_modules.htm
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句