-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.py
160 lines (136 loc) · 8.51 KB
/
home.py
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
import customtkinter as ctk
import os
from PIL import Image
import psycopg2
from Company.company import Company_Main_Frame
from Order.order import Order_Main_Frame
from Accounting.accounting import Accounting_Main_Frame
from Printdata.printdata import Printdata_Main_Frame
from sql import createdatatable, sv, back_up
class Select_Frame(ctk.CTkFrame):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)
self.copymsg = None
homeimg = Image.open(f"{os.getcwd()}\\icon\\home.png")
Rehomeimg = ctk.CTkImage(homeimg,size=(50,50))
self.btn_home = ctk.CTkButton(self ,text="" ,image=Rehomeimg ,width=160 ,height=160,
fg_color=("#5b5a5a"), corner_radius=0)
self.btn_home.grid(row=0, column=0)
copyimg = Image.open(f"{os.getcwd()}\\icon\\copy.png")
Recopyimg = ctk.CTkImage(copyimg,size=(50,50))
self.btn_copy = ctk.CTkButton(self ,text="" ,image=Recopyimg ,width=160 ,height=160,
fg_color=("#5b5a5a"), corner_radius=0,
command=sv)
self.btn_copy.grid(row=0, column=1)
restoreimg = Image.open(f"{os.getcwd()}\\icon\\restore.png")
Restoreimg = ctk.CTkImage(restoreimg,size=(50,50))
self.btn_restore = ctk.CTkButton(self ,text="" ,image=Restoreimg ,width=160 ,height=160,
fg_color=("#5b5a5a"), corner_radius=0,
command=back_up)
self.btn_restore.grid(row=0, column=2)
self.lab_other = ctk.CTkLabel(self, width = kwargs["width"]-480, height = kwargs["height"],
fg_color=("#5b5a5a"), text="")
self.lab_other.grid(row=0, column=3)
class Home_Main_Frame(ctk.CTkFrame):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)
wedge = kwargs["width"]/13
hedge = kwargs["height"]/6
#self.frame = ctk.CTkFrame(self, width=kwargs["width"],height=kwargs["height"],fg_color="green")
companyimg = Image.open(f"{os.getcwd()}\\icon\\company.png")
Recompanyimg = ctk.CTkImage(companyimg,size=(60,60))
self.btn_company = ctk.CTkButton(self ,text="" ,image=Recompanyimg ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_company.place(x=wedge*3, y=hedge)
self.lab_company = ctk.CTkLabel(self, text="公司管理", font=("microsoft yahei", 20, 'bold'), text_color=("#333333"))
self.lab_company.place(x=wedge*3+40, y=hedge*2+40)
orderimg = Image.open(f"{os.getcwd()}\\icon\\order.png")
Reorderimg = ctk.CTkImage(orderimg,size=(60,60))
self.btn_order = ctk.CTkButton(self ,text="" ,image=Reorderimg ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_order.place(x=wedge*3, y=hedge*3)
self.lab_order = ctk.CTkLabel(self, text="訂貨單輸入", font=("microsoft yahei", 20, 'bold'), text_color=("#333333"))
self.lab_order.place(x=wedge*3+30, y=hedge*4+40)
accountingimg = Image.open(f"{os.getcwd()}\\icon\\accounting.png")
Reaccountingimg = ctk.CTkImage(accountingimg,size=(60,60))
self.btn_accounting = ctk.CTkButton(self ,text="" ,image=Reaccountingimg ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_accounting.place(x=wedge*5, y=hedge)
self.lab_accounting = ctk.CTkLabel(self, text="入賬管理", font=("microsoft yahei", 20, 'bold'), text_color=("#333333"))
self.lab_accounting.place(x=wedge*5+40, y=hedge*2+40)
printimg = Image.open(f"{os.getcwd()}\\icon\\print.png")
Reprintimg = ctk.CTkImage(printimg,size=(60,60))
self.btn_print = ctk.CTkButton(self ,text="" ,image=Reprintimg ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_print.place(x=wedge*5, y=hedge*3)
self.lab_print = ctk.CTkLabel(self, text="明細單列印", font=("microsoft yahei", 20, 'bold'), text_color=("#333333"))
self.lab_print.place(x=wedge*5+30, y=hedge*4+40)
self.btn_other1 = ctk.CTkButton(self ,text="" ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_other1.place(x=wedge*7, y=hedge)
self.btn_other2 = ctk.CTkButton(self ,text="" ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_other2.place(x=wedge*7, y=hedge*3)
self.btn_other3 = ctk.CTkButton(self ,text="" ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_other3.place(x=wedge*9, y=hedge)
self.btn_other4 = ctk.CTkButton(self ,text="" ,width=160 ,height=160 ,
fg_color=("#DDDDDD"), text_color=("#5b5a5a"))
self.btn_other4.place(x=wedge*9, y=hedge*3)
#self.frame.grid(row=0,column=0,columnspan=3)
class App(ctk.CTk):
def __init__(self):
super().__init__()
w = self.winfo_screenwidth()
h = self.winfo_screenheight()
self.geometry(f"{w}x{h}+{0}+{0}")
self.title("Management System")
try:
con = psycopg2.connect(database="postgres", user="postgres", password="admin", host="localhost")
with con:
cur = con.cursor()
cur.execute(f"select * from customer")
except:
createdatatable()
#Select_Frame
self.Select_Frame = Select_Frame(self, width = w , height = 160, fg_color=("#5b5a5a"))
self.Select_Frame.grid(row=0, column=0, sticky='nsew')
#Main_Frame
self.Main_Frame = Home_Main_Frame(self, width = w , height = h-160, fg_color=("#FFFFFF"))
self.Main_Frame.grid(row=1, column=0, sticky='nsew')
#關掉主要的Frame開啟對應btn的Frame
#隱藏的方法 https://www.delftstack.com/zh-tw/howto/python-tkinter/how-to-hide-recover-and-delete-tkinter-widgets/
def open_home (event):
self.Main_Frame.destroy()
self.Main_Frame = Home_Main_Frame(self, width = w , height = h-160, fg_color=("#FFFFFF"))
self.Main_Frame.grid(row=1, column=0,sticky='nsew')
self.Main_Frame.btn_company.bind("<Button-1>", open_company)
self.Main_Frame.btn_order.bind("<Button-1>", open_order)
self.Main_Frame.btn_accounting.bind("<Button-1>", open_accounting)
self.Main_Frame.btn_print.bind("<Button-1>", open_printdata)
def open_company (event):
self.Main_Frame.destroy()
self.Main_Frame = Company_Main_Frame(self, width = w , height = h-160, fg_color=("#FFFFFF"))
self.Main_Frame.grid(row=1, column=0,sticky='nsew')
def open_order (event):
self.Main_Frame.destroy()
self.Main_Frame = Order_Main_Frame(self, width = w , height = h-160, fg_color=("#FFFFFF"))
self.Main_Frame.grid(row=1, column=0,sticky='nsew')
def open_accounting (event):
self.Main_Frame.destroy()
self.Main_Frame = Accounting_Main_Frame(self, width = w , height = h-160, fg_color=("#FFFFFF"))
self.Main_Frame.grid(row=1, column=0,sticky='nsew')
def open_printdata (event):
self.Main_Frame.destroy()
self.Main_Frame = Printdata_Main_Frame(self, width = w , height = h-160, fg_color=("#FFFFFF"))
self.Main_Frame.grid(row=1, column=0,sticky='nsew')
#切換功能
#btn事件教學 https://ithelp.ithome.com.tw/articles/10275712?sc=iThomeR
self.Select_Frame.btn_home.bind("<Button-1>", open_home)
self.Select_Frame.btn_restore.bind("<Button-1>", open_home)
self.Main_Frame.btn_company.bind("<Button-1>", open_company)
self.Main_Frame.btn_order.bind("<Button-1>", open_order)
self.Main_Frame.btn_accounting.bind("<Button-1>", open_accounting)
self.Main_Frame.btn_print.bind("<Button-1>", open_printdata)
app = App()
app.mainloop()