-2
私はtkinterとグラフィカルインターフェースを開発しています。私は、ファイルを開いて、それを送信すると、私はラベルにスクロールの指示を見てみたい(Commande)tkinterインターフェースが必要です
私はこの命令ですべて
へLabel(Frame1, text="Commande", background='NavajoWhite2').pack(padx=165, pady=10)
感謝をこの命令print('Sending: ' + l)
をリンクする方法がわからない、より正確には
from tkinter import *
from tkinter import filedialog
from tkinter import ttk, Text
#nom de la fenetre
moha = Tk()
moha.title('Emetteur G-code Universel')
moha.geometry("2500x2500")
moha['bg']= 'NavajoWhite2'
##################
##################
#le chemin de recherche #
def file(tk_event=None, *args, **kw):
fiile = filedialog.askopenfilename(filetypes=[('txt files','.txt'),('all files','.*')])
file_path.set(fiile)
fichier = open(fiile, "r")
print(fiile)
content_bis = fichier.readlines()
for line in content_bis:
T.insert(END, line)
fichier.close()
# Créer les différentes Frame
Outil = LabelFrame(moha, text="Outil")
Outil.place(x=500)
Outil['bg']= 'NavajoWhite2'
label = Label(Outil, text='Fichier : ', background='NavajoWhite2')
label.place(x=10, y=114)
file_path = StringVar()
entry = Entry(Outil, textvariable=file_path)
entry.place(x=60, y=114)
################
def moh():
# Open grbl serial port
s = serial.Serial('/dev/ttyS0',115200)
# Open g-code file
f = open(file_path.get(), "r");
# Wake up grbl
s.write("\r\n\r\n".encode('utf8'))
time.sleep(2) # Wait for grbl to initialize
s.flushInput() # Flush startup text in serial input
# Stream g-code to grbl
for line in f:
l = line.strip() # Strip all EOL characters for consistency
print ('Sending: ' + l)
s.write((l + '\n').encode("utf8")) # Send g-code block to grbl
grbl_out = s.readline().decode("utf8") # Wait for grbl response with carriage return
print (' : ' + grbl_out)
# Wait here until grbl is finished to close serial port and file.
raw_input(" Press <Enter> to exit and disable grbl.")
# Close file and serial port
f.close()
s.close()
#Créer la barre de recherche
#################
o = LabelFrame(moha, text="Fase des commandes")
o.place(y=400)
o['bg']= 'NavajoWhite2'
Label(o, background='NavajoWhite2').pack(padx=670,pady=120)
Frame1 = Frame(o, borderwidth=3, relief=GROOVE, background='NavajoWhite2')
Frame1.place(x=0, y=5)
Label(Frame1, text="Commande",background='NavajoWhite2').pack(padx=165, pady=10)
#################
b1= Button(Outil, text ="Commande", background='White').place(x=10, y=20)
b2= Button(Outil, text ="Fichier", background='White').place(x=110, y=20)
b3= Button(Outil, text ="Côntrole de la machine",
background='White').place(x=190, y=20)
b4= Button(Outil, text ="Selectionner un fichier",background='White',
command=file).place(x=235, y=112)
b5= Button(Outil, text ="Envoyer",background='White', command=moh).place(x=30, y=150)
b6= Button(Outil, text ="Pause",background='White').place(x=110, y=150)
b7= Button(Outil, text ="Annuler",background='White').place(x=180, y=150)
Label(Outil, text="", background='NavajoWhite2').pack(padx=300, pady=150)
################
################
S = Scrollbar(Outil, background='NavajoWhite2')
T = Text(Outil, height=19, width=28)
S.place(x=380, y=10)
T.place(x=400, y=0)
S.config(command=T.yview)
T.config(yscrollcommand=S.set)
あなたはテキストまたは' config'を法とラベルの任意の属性を更新することができます。以下は
は、これがどのように機能するかを示しているMinimal, Complete, and Verifiable exampleですl) '。 – Novel@Novel私は理解していませんでした:/ –
'print( 'Sending:' + l)'を 'label.config(text = 'Sending:' + l)'に置き換えると、ターミナルより。あなたが求めていたものではありませんか? – Novel