小弟搜尋也試過許多文章
發現在GUI中是不能使用sleep這個指令的
要用after 但是小弟想破頭還是想不出來要怎麼顯示在我的介面之中
於是我先將我使用python亂數生成的程式碼打包成亂數產生的執行檔exe
繼續再GUI程式碼之中打開exe之後 再去做讀取由亂數exe生成的記事本資料
但實在是沒有辦法運行 前幾天測試的時候只能顯示第一筆資料就卡住不動了
想在這邊請教有沒有高手神人可以幫幫小弟
而之前按鈕有反應 現在改到按下去都沒反應了
小弟初學者已經google到沒有辦法了 請求版上各大高手解惑...
#def ChillerPL():
def Data():
RRT = open(r'D:\Chiller_Program\4TEST(OFF2).txt') #讀取記事本數據 冷凍頓
SDSM = []
for line in RRT:
SDSM.append(line)
print(SDSM[0])
RRT.close()
SDSM1 = SDSM[0]
b = SDSM1
SDSM1.delete(0,"end")
SDSM1.insert(0, b)
root.after(1,Data)
def dis(event):
SDSM1 = tk.Entry(SDSM1[0],font = ft3,bg="yellow")
SDSM1.place(x=1220,y=120)
root.after(0,Data)
def btnPL(event):
root.after(0, Data)
btnSchedule = tk.Button(root,
text='執行調度',font = ft1, # 顯示文字
width=10, height=3)
#command=hit_me) # 執行之指令
btnSchedule.bind("<Button-1>",btnPL)
btnSchedule.place(x=10,y=320) # 位置布局
import tkinter as tk
import hashlib
logPath = "D:\\tmp\\20200514\\log.txt"
def Data():
log = ""
with open(logPath, 'r') as f:
for line in f.readlines():
log += line
__writeText(log)
root.after(1000, Data)
def __writeText(log):
#todo (add a consider to detect contents, if change to do this function)
text.delete(1.0, tk.END)
text.insert(tk.END, log)
def start():
print("start")
Data()
root = tk.Tk()
text = tk.Text(root)
text.place(x=1220,y=120)
text.pack()
btnSchedule = tk.Button(root,
text='執行調度', # 顯示文字
width=10, height=3
,command = start)
btnSchedule.place(x=10,y=320)
btnSchedule.pack()
root.mainloop()
太感謝您了 不過我現在有個小問題是
我想要TXT檔內特定行數的問題 text[0]內可以只讀取第一行內容
但[1]之後的都讀取不到 我有去爬過readline相關問題了
因為我想要將計算出來的資料分開到GUI內各個部分 用Label 或Entry來顯示都行
但我用出來畫面上顯示出來的都不是完整的數字 好像也顯示不出來 不曉得能否在請教您一下
單純的輸出已經完全OK了!!
root = tk.Tk() #建立視窗
root.title("Chiller") #視窗名稱
root.geometry("1600x980") #視窗大小
root.resizable(width=0, height=0) #鎖定視窗大小
canvas = tk.Canvas(root,
width = 1400, # 指定Canvas元件的寬度
height = 1000, # 指定Canvas元件的高度
bg = 'white') # 指定Canvas元件的背景色
#im = Tkinter.PhotoImage(file='img.gif') # 使用PhotoImage開啟圖片
image = Image.open("D:\冰水主機圖片\冰機人機介面繪圖004.gif")
im = ImageTk.PhotoImage(image)
canvas.create_image(720,480,image = im) # 使用create_image將圖片新增到Canvas元件中
canvas.pack(side="right") # 將Canvas新增到主視窗
ft1 = tkFont.Font(family="標楷體", size=20, weight=tkFont.BOLD) #按鈕字體設定
ft2 = tkFont.Font(family="標楷體", size=13, weight=tkFont.BOLD) #顯示文字字體設定
ft3 = tkFont.Font(family="標楷體", size=13, weight=tkFont.BOLD)
ft4 = tkFont.Font(family="標楷體", size=18, weight=tkFont.BOLD)
ft5 = tkFont.Font(family="標楷體", size=25, weight=tkFont.BOLD)
logPath = "D:\\Chiller_Program/4TEST(OFF2).TXT"
def Data():
log = ""
with open(logPath, 'r') as f:
for line in f.readline():
log += line
#print(line[0])
#print(log[0])
__writeText(log)
root.after(1000, Data)
#os.system("D:\Chiller_Program\dandom.exe")
def __writeText(log):
PL = text
PL = tk.Label(text = line,font = ft3,bg="yellow")
PL.place(x=1220,y=120)
#todo (add a consider to detect contents, if change to do this function)
text.delete(1.0, tk.END)
text.insert(tk.END, log)
def getSig(contents):
m = hashlib.md5(contents.encode())
return m.digest()
def start():
print("start")
Data()
#root = tk.Tk()
text = tk.Text(root)
#text.pack()
btnSchedule = tk.Button(root,
text='執行調度', # 顯示文字
width=10, height=3
,command = start)
btnSchedule.place(x=10,y=320)
#btnSchedule.pack()
root.mainloop()
import tkinter as tk
import hashlib
logPath = "D:\\tmp\\20200514\\log.txt"
def Data():
log = []
with open(logPath, 'r') as f:
log = f.read().splitlines()
#__writeText(log)
writePL(log)
root.after(1000, Data)
def writePL(log):
for index,singalLog in enumerate(log,start=1):
if index %6 == 0:
__writePL0(singalLog)
if index %6 == 1:
__writePL1(singalLog)
if index %6 == 2:
__writePL2(singalLog)
if index %6 == 3:
__writePL3(singalLog)
if index %6 == 4:
__writePL4(singalLog)
if index %6 == 5:
__writePL5(singalLog)
def __writePL0(string):
pL0String.set(string)
def __writePL1(string):
pL1String.set(string)
def __writePL2(string):
pL2String.set(string)
def __writePL3(string):
pL3String.set(string)
def __writePL4(string):
pL4String.set(string)
def __writePL5(string):
pL5String.set(string)
# def __writeText(log):
# #todo (add a consider to detect contents, if change to do this function)
# # text.delete(1.0, tk.END)
# # text.insert(tk.END, log)
# text.delete(1.0, tk.END)
# for singalLog in log:
# text.insert(tk.END, singalLog)
def start():
print("start")
Data()
root = tk.Tk()
text = tk.Text(root)
text.place(x=1220,y=120)
text.pack()
btnSchedule = tk.Button(root,
text='執行調度', # 顯示文字
width=10, height=3
,command = start)
btnSchedule.place(x=10,y=320)
pL0String = tk.StringVar()
pL0String.set("Nothing")
PL0 = tk.Label(root,textvariable = pL0String)
PL0.pack()
pL1String = tk.StringVar()
pL1String.set("Nothing")
PL1 = tk.Label(root,textvariable = pL1String)
PL1.pack()
pL2String = tk.StringVar()
pL2String.set("Nothing")
PL2 = tk.Label(root,textvariable = pL2String)
PL2.pack()
pL3String = tk.StringVar()
pL3String.set("Nothing")
PL3 = tk.Label(root,textvariable = pL3String)
PL3.pack()
pL4String = tk.StringVar()
pL4String.set("Nothing")
PL4 = tk.Label(root,textvariable = pL4String)
PL4.pack()
pL5String = tk.StringVar()
pL5String.set("Nothing")
PL5 = tk.Label(root,textvariable = pL5String)
PL5.pack()
root.mainloop()