# tkinter.Entry
import tkinter as tk
root = tk.Tk() # 初始化Tk()
root.title("entry-test") # 设置窗口标题
root.geometry("300x200") # 设置窗口大小 注意:是x 不是*
root.resizable(width=True, height=False) # 设置窗口是否可以变化长/宽,False不可变,True可变,默认为True
var = tk.StringVar()
e = tk.Entry(root, textvariable=var)
var.set("entry") # 设置文本框中的值
e.pack(side=tk.BOTTOM) # 这里的side可以赋值为LEFT--左 TOP--上 BOTTOM--下 RIGHT--右
root.mainloop() # 显示窗口()
# tkinter.Label
import tkinter as tk
root = tk.Tk() # 初始化Tk()
root.title("label-test") # 设置窗口标题
root.geometry("200x300") # 设置窗口大小 注意:是x 不是*
root.resizable(width=True, height=False) # 设置窗口是否可以变化长/宽,False不可变,True可变,默认为True
l = tk.Label(root, text="label", bg="blue", font=("Arial", 12), width=8, height=3)
l.pack(side=tk.BOTTOM) # 这里的side可以赋值为LEFT--左 TOP--上 BOTTOM--下 RIGHT--右
root.mainloop()
from tkinter import *
tk=Tk()
#标签控件,显示文本和位图,展示在第一行
Label(tk,text="First").grid(row=0,column=1)
Label(tk,text="Second").grid(row=1,column=1)#第二行
#主事件循环
mainloop()
# 安装
pip3 install requests
import requests
requests.get('http://httpbin.org/get')
requests.post('http://httpbin.org/post')
requests.put('http://httpbin.org/put')
requests.delete('http://httpbin.org/delete')
requests.head('http://httpbin.org/get')
requests.options('http://httpbin.org/get')
import requests
response = requests.get('http://www.baidu.com')
print(response.status_code) # 打印状态码
print(response.url) # 打印请求url
print(response.headers) # 打印头信息
print(response.cookies) # 打印cookie信息
print(response.text) #以文本形式打印网页源码
print(response.content) #以字节流形式打印
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null"
headers = {
"Host": " fanyi.youdao.com",
'Connection': 'keep - alive',
'Accept': ' application / json, text / javascript, * / *; q = 0.01',
'Origin': ' http: // fanyi.youdao.com',
'X - Requested - With': ' XMLHttpRequest',
'User - Agent': ' Mozilla / 5.0(WindowsNT10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 55.0.2883.87Safari / 537.36',
'Content - Type': ' application / x - www - form - urlencoded;charset = UTF - 8',
'Referer': ' http: // fanyi.youdao.com /',
'Accept - Encoding': 'gzip, deflate',
'Accept - Language': 'zh - CN, zh;q = 0.8'
}
formData = {
"type": "AUTO",
"i":word,
"from":"AUTO",
'to':'AUTO',
"smartresult":"dict",
"client":"fanyideskweb",
'salt':'1525516901332',
'sign':'a2616a82b1e43da512ed61c8dc09ec2c',
"doctype":"json",
"version":"2.1",
"keyfrom":"fanyi.web",
"action":"FY_BY_REALTIME",
"typoResult":"true"
}
response = requests.post(url=url, headers=headers, data=formData)
# print(response.text)
data = json.loads(response.text)['translateResult'][0][0]['tgt']
snipaste20180821_155724.jpg (17.14 KB, 下载次数: 10)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |