我把下面python打包以后,在自己的电脑上面可以正常运行,但是如果把他移植到别人电脑上面就连接不了数据库了(我们是一个公司的,用的一个网络,他电脑上面没有Python,没有数据库软件)
import winsound
import xlwt
import pyodbc
import tkinter as tk
window = tk.Tk()
window.title('my window')
window.geometry('300x300')
e = tk.Entry(window, show=None)
e.pack()
def set_style(name, height, bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
def write_excel(d):
f = xlwt.Workbook()
sheet1 = f.add_sheet('学生',cell_overwrite_ok=True)
row0 = ["model_desc","Model_serno","part_no","part_serno","part_desc","dtinput","mfg_date"]
#写第一行
for i in range(0,len(row0)):
sheet1.write(0,i,row0[i],set_style('Times New Roman',220,True))
#从第二行开始写从数据库里面捞出来的数据
for i in range(0,len(d)):
for m in range(0, len(d[i])):
sheet1.write(i + 1, m, d[i][m], set_style('Times New Roman', 220, True))
f.save('D:/'+tt+'.xls',)
global Mes1
Mes1 = None
def insert_point():
conn = pyodbc.connect(driver='SQL Server Native Client 11.0',server="1wwws",user="sss",password="ddd",database="pddd)
cur = conn.cursor()
global tt
tt=e.get()
if e.get()=='':
show_eff(False)
else:
cur.execute("select * from v_customer_require where part_no=?",e.get())
data = cur.fetchall()
if len(data) !=0:
t = []
d = []
for i in range(len(data)):
t.append(data[i][0])
t.append(data[i][1])
t.append(data[i][2])
t.append(data[i][3])
t.append(data[i][4])
t.append(data[i][5])
t.append(data[i][6])
d.append(t)
t = []
write_excel(d)
cur.close()
show_eff(True)
else:
show_eff(False)
def show_eff(e):
global Mes1
if Mes1 is None:
Mes1 = tk.Message(text = 'OK' if e else 'Fail', width = 60)
Mes1.pack()
else:
Mes1.pack_forget()
Mes1 = tk.Message(text = 'OK' if e else 'Fail', width = 60)
Mes1.pack()
if e==False:
winsound.Beep(900, 1000)
def windowset():
b1 = tk.Button(window, text='insert point', width=15,
height=2, command=insert_point)
b1.pack()
window.mainloop()
windowset()