Open sardine2 opened 7 years ago
what is .ttk ?? py2.0 or py3.0?
how to import tinter?
1.要么全导入:
from tkinter import *
root = Tk()
2.要么单独导入:
from tkinter import Tk
root = Tk()
3.要么只导入模块名称,然后引用时加模块名称做前缀:
import tkinter
root = tkinter.Tk()
就是说你得让python知道去哪里找这个对象。
from tkinter import*
与import tinter as tk
的区别?教练推荐后者。
What exactly does “import *” import?
The advantage of from X import * is that it allows you to be lazy. The problem of it is that it will bite you in the ass for lazy :)
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.pack()
self.create_widgets()
def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Hello World\n(click me)"
self.hi_there["command"] = self.say_hi
self.hi_there.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=root.destroy)
self.quit.pack(side="bottom")
def say_hi(self):
print("hi there, everyone!")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
本来觉得大猫把ch1每个功能都写成函数已经够呛,没料到 fatfox2016 把 ch1 全部用 class 进行了封装,丧心病狂啊!! 然后又倒回去看大猫 ch1 作业,发现还是有看不懂的地方。。。然后巩固了一下 len() 关于 str 以及 list 的不同点。 唉,好惭愧,也好残酷。
廖雪峰
如果要让内部属性不被外部访问,可以把属性的名称前加上两个下划线,在Python中,实例的变量名如果以开头,就变成了一个私有变量(private),只有内部可以访问,外部不能访问,所以,我们把Student类改一改:
一个实例详解
The Tkinter Grid Geometry Manager
tutorial