IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> Python_75-83 -> 正文阅读

[Python知识库]Python_75-83

from tkinter import *
root = Tk()
w1 = Message(root, text='这是一则消息', width=100)
w1.pack()
w2 = Message(root, text='这是一则骇人听闻的长长长长长长长长长长消息', width=100)
w2.pack()
mainloop()
============
from tkinter import *
root = Tk()
w1 = Spinbox(root, from_=0, to=10)
w1.pack()
mainloop()
===============
from tkinter import *
root = Tk()
w = Spinbox(root, values=('小甲鱼', '风介', 'wei', '戴宇轩'))
w.pack()
mainloop()
===============
from tkinter import *
m = PanedWindow(orient=VERTICAL)
m.pack(fill=BOTH, expand=1)
top = Label(m, text='Top Pane')
m.add(top)
bottom = Label(m, text='Bottom Pane')
m.add(bottom)
mainloop()
==============
from tkinter import *
m = PanedWindow(orient=VERTICAL)#默认为左右,vertical为垂直分割
#BOTH表示全局填充,expand表示有1条分割线
m.pack(fill=BOTH, expand=1)
top = Label(m, text='Top Pane')
m.add(top)
bottom = Label(m, text='Bottom Pane')
m.add(bottom)
mainloop()
============
from tkinter import *
m1 = PanedWindow(showhandle=True, sashrelief=SUNKEN)
#是否显示handle小方块,分割线样式,往下凹
m1.pack(fill=BOTH, expand=1)
left = Label(m1, text='LEFT Pane')
m1.add(left)

m2 = PanedWindow(orient=VERTICAL, showhandle=True, sashrelief=SUNKEN)
m1.add(m2)
top = Label(m2, text='Top Pane')
m2.add(top)
bottom = Label(m2, text='Bottom Pane')
m2.add(bottom)
mainloop()
=============
from tkinter import *
root = Tk()
def create():
    top = Toplevel()
    top.title('FishC Demo')
    top.attributes('-alpha', 0.5)
    msg = Message(top, text='大家好,我是渣渣辉!')
    msg.pack()
Button(root, text='创建顶级窗口', command=create).pack()
mainloop()
==============
from tkinter import *
root = Tk()
listbox = Listbox(root)
listbox.pack(fill=BOTH, expand=True)#True是指窗口拓展的时候也能填充进去
#fill=X表示横向填充,fill=Y表示纵向填充,fill=BOTH是横向和纵向
for i in range(10):
    listbox.insert(END, str(i))
mainloop()
#pack默认是纵向填充
===============
from tkinter import *
root = Tk()
Label(root, text='用户名').grid(row=0, column=0, sticky=W)
Label(root, text='密码').grid(row=1, column=0, sticky=W)

photo = PhotoImage('logo.gif')
Label(root, image=photo).grid(row=0, column=2, rowspan=2, padx=5, pady=5)

Entry(root).grid(row=0, column=1)
Entry(root, show='*').grid(row=1, column=1)

Button(text='提交', width=10).grid(row=2, column=0, columnspan=3, pady=5)

mainloop()
=================
from tkinter import *
root = Tk()
photo = PhotoImage('logo_big.gif')
Label(root, image=photo).pack()
def callback():
    print('正中靶心!')
Button(root, text='点我!', command=callback)\
    .place(relx=0.5, rely=0.5, anchor=CENTER)
#相对距离 0.5表示正中心,
mainloop()
==============
from tkinter import *
root = Tk()
Label(root, bg='red').place(relx=0.5, rely=0.5, \ 
relheight=0.75, relwidth=0.75, anchor=CENTER)
#下个组件的相对高度和宽度
Label(root, bg='yellow').place(relx=0.5, rely=0.5, \
relheight=0.5, relwidth=0.5, anchor=CENTER)
Label(root, bg='green').place(relx=0.5, rely=0.5, \
relheight=0.25, relwidth=0.25, anchor=CENTER)
mainloop()
from tkinter import *
from tkinter import messagebox
print(messagebox.askokcancel('FishC demp', '发射核弹?'))
mainloop()
================
from tkinter import *
from tkinter.filedialog import askopenfilename
root = Tk()

def callback():
    fileName = askopenfilename(filetypes=[('PNG', '.PNG'), ('JPG', '.jpg'), ('GIF', '.gif'), ('PYTHON', '.py')])
    print(fileName)
Button(root, text='打开文件', command=callback).pack()

mainloop()
==================
from tkinter import *
from tkinter.colorchooser import askcolor
root = Tk()
def callback():
    filename = askcolor()
    print(filename)

Button(root, text='选择颜色', command=callback).pack()

mainloop()
================
import pygame
import sys
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()
size = width, height = 1200, 800
speed = [-2, 1]
bg = (255, 255, 255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('初次见面,请大家多多关照!')
turtle = pygame.image.load(r'E:\vippython\lena.jpg')
position = turtle.get_rect()
l_head = turtle
r_head = pygame.transform.flip(turtle, True, False)
while(True):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                turtle = l_head
                speed = [-1, 0]
            if event.key == K_RIGHT:
                turtle = r_head
                speed = [1, 0]
            if event.key == K_UP:
                speed = [0, -1]
            if event.key == K_DOWN:
                speed = [0, 1]
    position = position.move(speed)
    if position.left < 0 or position.right > width:
        pygame.transform.flip(turtle, True, False)
        speed[0] = -speed[0]
    if position.top < 0 or position.bottom > height:
        speed[1] = -speed[1]
    screen.fill(bg)
    screen.blit(turtle, position)
    pygame.display.flip()
    clock.tick(200)#最高的帧率
    pygame.time.delay(10)
#surface对象是pygame里面用来表示图像的对象
================81.1
import pygame
import sys
pygame.init()
size = width, height = 600, 400
screen = pygame.display.set_mode(size)
pygame.display.set_caption('初次见面,请多关照!!')
f = open('record.txt', 'w')
while True:
    for event in pygame.event.get():
        f.write(str(event) + '\n')
        if event.type == pygame.QUIT:
            f.close()
            sys.exit()
#(0, 0, 0)左键 中键 右键 是否被按下 pos图像中的位置, 相对于上一个的位置
#key是ascall码
==================81.2
import sys
import pygame
pygame.init()
size = width, height = 600, 400
bg = (0, 0, 0)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('FishC Demo')

font = pygame.font.Font(None, 20)
line_height = font.get_linesize()
position = 0
screen.fill(bg)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
    screen.blit(font.render(str(event), True, (0, 255, 0)), (0, position))
    position += line_height
    if position > height:
        position = 0
        screen.fill(bg)
    pygame.display.flip()
===================82.1
import pygame
import sys
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()
size = width, height = 1200, 800
bg = (255, 255, 255)



fullscreen = False
ratio = 1.0
screen = pygame.display.set_mode(size, RESIZABLE)
pygame.display.set_caption('初次见面,请大家多多关照!')

oturtle = pygame.image.load(r'E:\vippython\lena.jpg')
turtle = oturtle
oturtle_rect = oturtle.get_rect()
position = turtle_rect = oturtle_rect

speed = [5, 0]
turtle_right = pygame.transform.rotate(turtle, 90)
turtle_top = pygame.transform.rotate(turtle, 180)
turtle_left = pygame.transform.rotate(turtle, 270)
turtle_bottom = turtle
turtle = turtle_top

l_head = turtle
r_head = pygame.transform.flip(turtle, True, False)
while(True):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                turtle = l_head
                speed = [-1, 0]
            if event.key == K_RIGHT:
                turtle = r_head
                speed = [1, 0]
            if event.key == K_UP:
                speed = [0, -1]
            if event.key == K_DOWN:
                speed = [0, 1]
            if event.key == K_F11:
                fullscreen = not fullscreen
                if fullscreen:
                    screen = pygame.display.set_mode((1920, 1080), FULLSCREEN | HWSURFACE)
                    width, height = 1920, 1080
                else:
                    screen = pygame.display.set_mode(size)
            if event.key == K_EQUALS or event.key == K_MINUS or event.key == K_SPACE:
                if event.key == K_EQUALS and ratio < 2:
                    ratio += 0.1
                if event.key == K_MINUS and ratio > 0.5:
                    ratio -= 0.1
                if event.key == K_SPACE:
                    ratio = 1
                turtle = pygame.transform.smoothscale(oturtle, (int(oturtle_rect.width * ratio), int(oturtle_rect.height * ratio)))


        if event.type == VIDEORESIZE:
            size = event.size
            width, height = size
            print(size)
            screen = pygame.display.set_mode(size, RESIZABLE)

    position = position.move(speed)
    if position.right > width:
        turtle = turtle_right
        position = turtle_rect = turtle.get_rect()
        position.left = width - turtle_rect.width
        speed = [0, 5]
    if position.bottom > height:
        turtle = turtle_bottom
        position = turtle_rect = turtle.get_rect()
        position.left = width - turtle_rect.width
        position.top = height - turtle_rect.height
        speed = [-5, 0]
    if position.left < 0:
        turtle = turtle_left
        position = turtle_rect = turtle.get_rect()
        position.top = height - turtle_rect.height
        speed = [0, -5]
    if position.top < 0:
        turtle = turtle_top
        position = turtle_rect = turtle.get_rect()
        speed = [5, 0]

    if position.left < 0 or position.right > width:
        pygame.transform.flip(turtle, True, False)
        speed[0] = -speed[0]
    if position.top < 0 or position.bottom > height:
        speed[1] = -speed[1]
    screen.fill(bg)
    screen.blit(turtle, position)
    pygame.display.flip()
    clock.tick(200)#最高的帧率
    pygame.time.delay(10)
====================82.2
#set_mode resolution指定界面尺寸 指定拓展选项 指定颜色位数
import pygame
pygame.init()
print(pygame.display.list_modes())
==================82.3
import pygame
import sys
pygame.init()

select = 0
drag = 0
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        elif event.type == MOUSEBUTTONDOWN:
            if event.button == 1:
                if select == 0 and drag == 0:
                    select= 1
                elif select == 2 and drag == 0:
                    drag = 1
                elif select == 2 and drag == 2:
                    select = 2
        elif event.type == MOUSEBUTTONUP:
            if event.button == 1:
                if select == 1 and drag == 0:
                    select = 2
                if select == 2 and drag == 1:
                    drag = 2
    screen.fill(bg)
    screen.blit(turtle, position)
====================83.1
import pygame
import sys
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()
size = width, height = 640, 400
bg = (0, 0, 0)

screen = pygame.display.set_mode(size, RESIZABLE)
pygame.display.set_caption('FishC Demo')

turtle = pygame.image.load(r'E:\vippython\lena.jpg').convert()
background = pygame.image.load(r'E:\vippython\计数.png').convert()

position = turtle.get_rect()
position.center = width // 2, height // 2

while(True):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    screen.blit(background, (0, 0))
    screen.blit(turtle, position)
    pygame.display.flip()
    clock.tick(30)#最高的帧率
  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-10-28 12:20:59  更:2021-10-28 12:23:31 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 22:53:06-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码