[Python] 纯文本查看 复制代码
# !/user/bin/env Python3
# -*- coding:utf-8 -*-
from tkinter import *
from math01 import fun
from chinese import ch_zn
from english import Eng
root = Tk()
root.title('Learning tools')
root.geometry('400x600')
root.resizable(False,False)
#加载图片
bac = PhotoImage(file = './images/bac1.png')
bac1 = Label(image=bac)
bac1.grid(column=0,row = 3,sticky = W,padx = 0,pady = 5)
img = PhotoImage(file = './images/02.png')
img1 = Label(image=img)
img1.grid(column=0,row = 0,sticky = W,padx = 0,pady = 5)
img2 = PhotoImage(file = './images/03.png')
img3 = Label(image=img2)
img3.grid(column=0,row = 1,sticky = W,padx = 0,pady = 5)
img3 = PhotoImage(file = './images/04.png')
img4 = Label(image=img3)
img4.grid(column=0,row = 2,sticky = W,padx = 0,pady = 5)
#def printInfo0():
#fun()
#print('数学模块')
#创建三个按钮
b1=Button(root, text='数学',bg='#1bd7b7',command =fun , relief='raised', width=10, height=2)
b1.grid(column=0, row=0,sticky=W,padx=5,pady=5)
b2=Button(root, text='语文',bg='#8a1bd7',command =ch_zn , relief='raised', width=10, height=2)
b2.grid(column=0, row=1,sticky=W,padx=5,pady=5)
b3=Button(root, text='英语',bg='#eca20e',command =Eng , relief='raised', width=10, height=2)
b3.grid(column=0, row=2,sticky=W,padx=5,pady=5)
root.mainloop()
# !/user/bin/env Python3
# -*- coding:utf-8 -*-
from tkinter.ttk import *
from tkinter import *
def printInfo():
entry2.delete(0, END)
R = int(entry1.get())
S = round(3.14 * R * R,2)
entry2.insert(10, S)
entry1.delete(0, END)
def new():
global entry1,entry2
root = Tk()
root.title('求圆面积')
root.geometry('320x240')
Label(root, text="输入半径").grid(row=0)
Label(root, text="结 果").grid(row=1)
# Entry控件布局
entry1 = Entry(root)
entry2 = Entry(root)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
# Quit按钮退出;Run按钮打印计算结果
Button(root, text='计 算',command = printInfo).grid(row=2, column=1, sticky=W, padx=0, pady=0)
def calc(event):
t3.delete(0, END)
a = float(t1.get())
b = float(t2.get())
dic = {0:a+b,1:a-b,2:a*b,3:a/b}
c = dic[comb.current()]
t3.insert(10, c)
def calcs():
global t1,t2,t3,comb
root = Tk()
root.title('四则运算')
root.geometry('320x240')
Label(root, text="输入数字1").grid(row=0)
Label(root, text="输入数字2").grid(row=1)
Label(root, text="运算方式").grid(row=3)
t1 = Entry(root)
t2 = Entry(root)
t3 = Entry(root)
t1.grid(row=0, column=1)
t2.grid(row=1, column=1)
t3.grid(row=7, column=1)
var = StringVar()
comb = Combobox(root,textvariable=var,values=['加','减','乘','除',])
comb.grid(row=4,column=1)
comb.bind('<<ComboboxSelected>>',calc)
lbl=Label(root).grid(row=5,column=0)
lbl=Label(root).grid(row=6,column=0)
lbl=Label(root,text='结果').grid(row=7,column=0)
root.mainloop()
def None1():
pass
def tt(root1):
lb = Label(root1,text='math',\
bg='#66cccc',\
fg='skyblue',\
font=('华文新魏',32),\
width=300,\
height=300,\
relief=SUNKEN)
lb.pack()
def fun():
root1 = Tk()
root1.title('math')
root1.geometry('300x300')
root1.resizable(False,False)
tt(root1)
#创建三个按钮
b1=Button(root1, text='计算圆面积',bg='#FF7F00',command =new , relief='raised', width=10, height=2)
#b1.grid(column=0, row=0,sticky=W,padx=5,pady=5)
b1.place(relx=0.01, rely=0.1, relwidth=0.3, relheight=0.1)
b2=Button(root1, text='四则运算',bg='#FF7F00',command =calcs , relief='raised', width=10, height=2)
#b2.grid(column=0, row=1,sticky=W,padx=5,pady=5)
b2.place(relx=0.01, rely=0.3, relwidth=0.3, relheight=0.1)
b3=Button(root1, text='其 他',bg='#FF7F00',command =None1 , relief='raised', width=10, height=2)
#b2.grid(column=0, row=1,sticky=W,padx=5,pady=5)
b3.place(relx=0.01, rely=0.5, relwidth=0.3, relheight=0.1)
root1.mainloop()
# !/user/bin/env Python3
# -*- coding:utf-8 -*-
from tkinter.ttk import *
from tkinter import *
import tkinter as tk
from tkinter import filedialog, dialog
import os
file_path = ''
file_text = ''
def open_file():
'''
打开文件
:return:
'''
global file_path
global file_text
file_path = filedialog.askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('H:/')))
print('打开文件:', file_path)
if file_path is not None:
with open(file=file_path, mode='r+', encoding='utf-8') as file:
file_text = file.read()
text1.insert('insert', file_text)
def save_file():
global file_path
global file_text
file_path = filedialog.asksaveasfilename(title=u'保存文件')
print('保存文件:', file_path)
file_text = text1.get('1.0', tk.END)
if file_path is not None:
with open(file=file_path, mode='a+', encoding='utf-8') as file:
file.write(file_text)
text1.delete('1.0', tk.END)
dialog.Dialog(None, {'title': 'File Modified', 'text': '保存完成', 'bitmap': 'warning', 'default': 0,
'strings': ('OK', 'Cancle')})
print('保存完成')
def new():
global text1
window = tk.Tk()
window.title('notebook') # 标题
window.geometry('500x500') # 窗口尺寸
text1 = tk.Text(window, width=50, height=20, bg='#EECBAD', font=('Arial', 12))
text1.pack()
bt1 = tk.Button(window, text='打开文件', width=15, height=2, command=open_file)
bt1.pack()
bt2 = tk.Button(window, text='保存文件', width=15, height=2, command=save_file)
bt2.pack()
window.mainloop() # 显示
def None1():
pass
def tt(root1):
lb = Label(root1,text='Chinese',\
bg='#AB82FF',\
fg='purple',\
font=('华文新魏',32),\
width=300,\
height=300,\
relief=SUNKEN)
lb.pack()
def ch_zn():
root1 = Tk()
root1.title('Chinese')
root1.geometry('300x300')
root1.resizable(False,False)
tt(root1)
#创建三个按钮
b1=Button(root1, text='记事本',fg='white',bg='#8B4513',command =new , relief='raised', width=10, height=2)
#b1.grid(column=0, row=0,sticky=W,padx=5,pady=5)
b1.place(relx=0.01, rely=0.1, relwidth=0.3, relheight=0.1)
b3=Button(root1, text='其 他',fg='white',bg='#8B4513',command =None1 , relief='raised', width=10, height=2)
#b2.grid(column=0, row=1,sticky=W,padx=5,pady=5)
b3.place(relx=0.01, rely=0.3, relwidth=0.3, relheight=0.1)
root1.mainloop()
# !/user/bin/env Python3
# -*- coding:utf-8 -*-
from tkinter.ttk import *
from tkinter import *
import random
import tkinter as tk
word=['red','blue','yellow','green','pen','pencil','ruler','book','newspaper','notebook','dictionary','foot']
mean=['红','蓝','黄','绿','钢笔','铅笔','尺子','书','报纸','笔记本','词典','脚']
l=['']*12#标签
bt=[['']*5]*12#按钮
c=0#计数
def hit_me1(event):#按钮正确答案
event.widget["bg"]='green'#绿色表示正确
def hit_me2(event):#按钮错误答案
event.widget["bg"]='red'#红色表示错误
def hit_me3(event):#按钮下一页
global c,l,bt
if c>= len(word)-1:
c=0
l=['']*12#标签
bt=[['']*5]*12#按钮
try:
for i in range(5):
bt[c][i].destroy()#删掉上一页的按钮
l[c].destroy()#删掉上一页的标签
except:
Label(window, text="恭喜完成!").pack()
Button(window, text='Quit', command=window.quit).pack()
#偷懒复制粘贴
j=random.randint(0,len(word)-1)
#print(j)
#print(word[j],": ")
k=random.randint(0,3)
var = StringVar()
var.set(word[j])
l[c] = Label(window, textvariable=var, bg='#9966ff',fg='white', font=('Arial', 12), width=50, height=2)
l[c] =tk.Label(window, text=word[j], bg='#9966ff',fg='white', font=('Arial', 12), width=50, height=2)
l[c].pack()
for z in range(4):
if(z==k):
bt[c][z]=(tk.Button(window, text=mean[j], width=35, height=2))
bt[c][z].pack()
else:
bt[c][z]=(tk.Button(window, text=mean[random.randint(0,len(word)-1)], width=35, height=2))
bt[c][z].pack()
for i in range(4):
if(bt[c][i].config('text')[-1]==mean[j]):
bt[c][i].bind("<Button-1>",hit_me1)
else:
bt[c][i].bind("<Button-1>",hit_me2)
bt[c][4]=tk.Button(window, text='下一个', width=15, height=2)
bt[c][4].bind("<Button-1>",hit_me3)
bt[c][4].pack()
def main():
global window,word,mean
# 主窗口
window = tk.Tk()
window.title("Word") # 窗口标题
window.geometry('400x500') # 窗口尺寸
window.resizable(False,False)
j=random.randint(0,len(word)-1)
#print(j)
#print(word[j],": ")
k=random.randint(0,3)
#标签
var = StringVar()
var.set(word[j])
l[c] = Label(window, textvariable=var, bg='#9966ff',fg='white', font=('Arial', 12), width=50, height=2)
l[c] = tk.Label(window, text=word[j], bg='#9966ff',fg='white', font=('Arial', 12), width=50, height=2)
l[c].pack()
# 按钮
for z in range(4):
if(z==k):
bt[c][z]=(tk.Button(window, text=mean[j], width=35, height=2))
bt[c][z].pack()#正确答案随机放在四个选项中
else:
bt[c][z]=(tk.Button(window, text=mean[random.randint(0,len(word)-1)], width=35, height=2))
bt[c][z].pack()
for i in range(4):
if(bt[c][i].config('text')[-1]==mean[j]):
bt[c][i].bind("<Button-1>",hit_me1)
else:
bt[c][i].bind("<Button-1>",hit_me2)
bt[c][4]=(tk.Button(window, text='下一个', width=15, height=2))
bt[c][4].bind("<Button-1>",hit_me3)
bt[c][4].pack()
window.mainloop()
def calcs():
pass
def tt(root1):
lb = Label(root1,text='English',\
bg='#4682B4',\
fg='skyblue',\
font=('华文新魏',32),\
width=300,\
height=300,\
relief=SUNKEN)
lb.pack()
def Eng():
root1 = Tk()
root1.title('English')
root1.geometry('300x300')
root1.resizable(False,False)
tt(root1)
#创建三个按钮
b1=Button(root1, text='单词检查机',fg='red',bg='#CAFF70',command =main , relief='raised', width=10, height=2)
#b1.grid(column=0, row=0,sticky=W,padx=5,pady=5)
b1.place(relx=0.01, rely=0.1, relwidth=0.3, relheight=0.1)
b2=Button(root1, text='其 他',fg='red',bg='#CAFF70',command =calcs , relief='raised', width=10, height=2)
#b2.grid(column=0, row=1,sticky=W,padx=5,pady=5)
b2.place(relx=0.01, rely=0.3, relwidth=0.3, relheight=0.1)
root1.mainloop()