121.4_python_tkinter图片轮子初探GUI

本文最后更新于:4 个月前


研究了一些python的面向对象及类的使用,写了个这玩意 第三天:修复一个bug

序号溢出的问题

1
2
3
4
5
6
7
8
9
10
11
12
def chm(inumi,):
inumii=int(inumi)
if inumii>296:
inumii=0
print("numresset0")
elif inumii<0:
inumii=296
print("numreset296")
else:
inumii=inumii
inum.inum=inumii
return inumii

第二天:增加了辅助索引

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import tkinter as tk
from PIL import Image, ImageTk
import os,sys

imgs = datanames = os.listdir('path')
imgdex = "path/"
#print(imgs)
dict_pagenum2 = {
4:0,8:42,9:49,10:67,11:94,12:119,13:139,14:157,0:175,1:210,2:214,3:252,5:285,6:312,7:347
}
dict_pagenum = {
4:0,8:31,9:34,10:44,11:71,12:82,13:96,14:126,0:132,1:158,2:160,3:204,5:230,6:255,7:269
}
dict_pagename = {
0:"损伤适应",1:"修复",2:"循环障碍",3:"炎症",4:"肿瘤",5:"心血管",6:"呼吸",7:"消化",8:"淋巴",9:"泌尿",10:"生殖",11:"内分泌",12:"神经",13:"传染",14:"寄生虫"
}
class picnum():
def __init__(self) -> None:
self.inum = 0
def mirror():
imgs= os.listdir('path')
imgdex = "path/"
return imgdex,imgs[inum.inum]
def to_body():
imgs= os.listdir('path')
imgdex = "path/"
return imgdex,imgs[inum.inum]
def init_(root,imgdex=imgdex,path=imgs[0]):
paned = tk.PanedWindow(root)
paned.pack(fill=tk.X, side=tk.LEFT)
img = Image.open(imgdex+path)
paned.photo = ImageTk.PhotoImage(img.resize((900, 800)))
tk.Label(paned, image=paned.photo).grid(row=0, column=0)

class basedesk():
"""
根页面初始化
"""
def __init__(self,master):

self.root = master
self.root.wm_geometry("980x800+68-5")
self.root.resizable(0, 0)
#self.root.geometry('200x200')
#face2(self.root)
initface(self.root)

class initface():
"""
页面1
"""
def __init__(self,master):

self.master = master
#基准界面initface
self.initface = tk.Frame(self.master,)
self.initface.pack()
init_(self.initface,imgdex,imgs[inum.inum])
btn = tk.Button(self.initface,text='next',command=self.change)
btn.pack()
btn_back = tk.Button(self.initface,text='back',command=self.back)
btn_back.pack()
btntobo = tk.Button(self.initface,text='to_mirror',command=self.to_mirror)
btntobo.pack()
btncra(root_=self.master,master=self.initface)

def to_mirror(self):
inum.inum+=1
self.initface.destroy()
face2(self.master)
def change(self,):
inum.inum+=1
self.initface.destroy()
face1(self.master)

def back(self):
inum.inum-=1
self.initface.destroy()
face1(self.master)

class face1():
"""
页面2
"""
def __init__(self,master):
self.master = master
self.face1 = tk.Frame(self.master,)
self.face1.pack()
init_(self.face1,imgdex,imgs[inum.inum])
btn1 = tk.Button(self.face1,text='next',command=self.change)
btn1.pack()
btn_back = tk.Button(self.face1,text='back',command=self.back)
btn_back.pack()
btnmirr = tk.Button(self.face1,text='to_mirror',command=self.mirror)
btnmirr.pack()
btncra(root_=self.master,master=self.face1)

def back(self):
inum.inum-=1
self.face1.destroy()
initface(self.master)

def change(self,):
inum.inum+=1
self.face1.destroy()
initface(self.master)
def mirror(self):
inum.inum+=1
self.face1.destroy()
face2(self.master)

class face2():
"""
页面3
"""
def __init__(self,master):
self.master = master
self.face1 = tk.Frame(self.master,)
self.face1.pack()
a,b=mirror()
init_(self.face1,a,b)
btn1 = tk.Button(self.face1,text='next',command=self.change)
btn1.pack()
btn_back = tk.Button(self.face1,text='back',command=self.back)
btn_back.pack()
btnmirr = tk.Button(self.face1,text='to_body',command=self.to_body)
btnmirr.pack()
btncram(root_=self.master,master=self.face1)
def to_body(self):
self.face1.destroy()
initface(self.master)
def back(self):
inum.inum-=1
self.face1.destroy()
face3(self.master)
def change(self,):
inum.inum+=1
self.face1.destroy()
face3(self.master)

class face3():
"""
页面2
"""
def __init__(self,master):
self.master = master
self.face1 = tk.Frame(self.master,)
self.face1.pack()
a,b=a,b=mirror()
init_(self.face1,a,b)
btn1 = tk.Button(self.face1,text='next',command=self.change)
btn1.pack()
btn_back = tk.Button(self.face1,text='back',command=self.back)
btn_back.pack()
btnmirr = tk.Button(self.face1,text='to_body',command=self.to_body)
btnmirr.pack()
btncram(root_=self.master,master=self.face1)

def back(self):
inum.inum-=1
self.face1.destroy()
face2(self.master)

def change(self,):
inum.inum+=1
self.face1.destroy()
face2(self.master)
def to_body(self):
self.face1.destroy()
initface(self.master)

def btncra(root_,master):
ino = 0
dict_yema={}
for ino in range(0,15):
# dict_com[ino]=topage(func=root_,master=master,pagenum=ino)
aaaa = yema(master,num_func=ino,topage=ino,pagenum=dict_pagenum[ino])
dict_yema[ino]=aaaa
#print(dict_yema)
print(inum.inum,"body")
def btncram(root_,master):
ino = 0
dict_yema={}
for ino in range(0,15):
# dict_com[ino]=topage(func=root_,master=master,pagenum=ino)
aaaa = yema(master,num_func=ino,topage=ino,pagenum=dict_pagenum2[ino])
dict_yema[ino]=aaaa
#print(dict_yema)
print(inum.inum,"mirror")


class yema():
def __init__(self,master,num_func=0,topage=0,pagenum=dict_pagenum[0]):
self.master = master
self.pagenum = pagenum
self.dic_n={}
self.dic_n[num_func] = tk.Button(
self.master,
text=dict_pagename[topage],
command=lambda:changepage(self.pagenum)
)
for self.i in self.dic_n:
self.dic_n[self.i].pack()
#self.dic_n[self.i].bind("<Button-1>",changepage(pagenum=int(topage))
#)
def changepage(pagenum=dict_pagenum[0]):
inum.inum=pagenum
print(pagenum,inum.inum,"赋值成功!")

if __name__ == '__main__':
inum =picnum()
root = tk.Tk()
root.title('病理 view2')
basedesk(root)

#init_(root,imgs[3])
root.mainloop()

效果图:

image-20211206003416337

image-20211206003455511

image-20211206003600720

第一天的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import tkinter as tk
import tkinter.messagebox
import copy
from PIL import Image, ImageTk
import os,sys
imgs = datanames = os.listdir('pathname')
imgdex = "pathname/"
print(imgdex)

def mirror():
imgs= os.listdir('pathname')
imgdex = "pathname/"
return imgdex,imgs[inum.inum]
def to_body():
imgs= os.listdir('pathname')
imgdex = "pathname/"
return imgdex,imgs[inum.inum]


class basedesk():
"""
根页面
"""
def __init__(self,master):

self.root = master
self.root.wm_geometry("880x650+200-100")
self.root.resizable(0, 0)
#self.root.geometry('200x200')
face2(self.root)
def init_(root,imgdex=imgdex,path=imgs[0]):
paned = tk.PanedWindow(root)
paned.pack(fill=tk.X, side=tk.LEFT)
img = Image.open(imgdex+path)
paned.photo = ImageTk.PhotoImage(img.resize((800, 650)))
tk.Label(paned, image=paned.photo).grid(row=0, column=0)

class initface():
"""
页面1
"""
def __init__(self,master):

self.master = master
#基准界面initface
self.initface = tk.Frame(self.master,)
self.initface.pack()
init_(self.initface,imgdex,imgs[inum.inum])
btn = tk.Button(self.initface,text='next',command=self.change)
btn.pack()
btn_back = tk.Button(self.initface,text='back',command=self.back)
btn_back.pack()
btntobo = tk.Button(self.initface,text='to_mirror',command=self.to_mirror)
btntobo.pack()
def to_mirror(self):
inum.inum+=1
self.initface.destroy()
face2(self.master)
def change(self,):
inum.inum+=1
self.initface.destroy()
face1(self.master)

def back(self):
inum.inum-=1
self.initface.destroy()
face1(self.master)


class face2():
"""
页面3
"""
def __init__(self,master):
self.master = master
self.face1 = tk.Frame(self.master,)
self.face1.pack()
a,b=mirror()
init_(self.face1,a,b)
btn1 = tk.Button(self.face1,text='next',command=self.change)
btn1.pack()
btn_back = tk.Button(self.face1,text='back',command=self.back)
btn_back.pack()
btnmirr = tk.Button(self.face1,text='to_body',command=self.to_body)
btnmirr.pack()
def to_body(self):
self.face1.destroy()
initface(self.master)
def back(self):
inum.inum-=1
self.face1.destroy()
face3(self.master)

def change(self,):
inum.inum+=1
self.face1.destroy()
face3(self.master)
class picnum():
def __init__(self) -> None:
self.inum = 0


class face1():
"""
页面2
"""
def __init__(self,master):
self.master = master
self.face1 = tk.Frame(self.master,)
self.face1.pack()
init_(self.face1,imgdex,imgs[inum.inum])
btn1 = tk.Button(self.face1,text='next',command=self.change)
btn1.pack()
btn_back = tk.Button(self.face1,text='back',command=self.back)
btn_back.pack()
btnmirr = tk.Button(self.face1,text='to_mirror',command=mirror)
btnmirr.pack()

def back(self):
inum.inum-=1
self.face1.destroy()
initface(self.master)

def change(self,):
inum.inum+=1
self.face1.destroy()
initface(self.master)
def mirror(self):
inum.inum+=1
self.face1.destroy()
face2(self.master)


class face3():
"""
页面2
"""
def __init__(self,master):
self.master = master
self.face1 = tk.Frame(self.master,)
self.face1.pack()
a,b=a,b=mirror()
init_(self.face1,a,b)
btn1 = tk.Button(self.face1,text='next',command=self.change)
btn1.pack()
btn_back = tk.Button(self.face1,text='back',command=self.back)
btn_back.pack()
btnmirr = tk.Button(self.face1,text='to_body',command=self.to_body)
btnmirr.pack()

def back(self):
inum.inum-=1
self.face1.destroy()
face2(self.master)

def change(self,):
inum.inum+=1
self.face1.destroy()
face2(self.master)
def to_body(self):
self.face1.destroy()
initface(self.master)

if __name__ == '__main__':
inum =picnum()
root = tk.Tk()
basedesk(root)

#init_(root,imgs[3])
root.mainloop()

效果

image-20211204174933865

image-20211204175015236


在这里给我留言👇