Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter
#14
hi guys...
what's wrong with this code?
as you can see, I'm tested with different methods and do the same thing,
it shows the windows at the end of the procedure, I want the window showing the messages one after another

from tkinter import *
import tkinter as tk
from tkinter import scrolledtext
import os
import keyboard
import serial
import time

def on_closing():
	pass

def Ready():
	keyboard.wait('y'or 'Y')
	ser4.open()
	ser4.write(b'\x00')
	ser4.write(b'\x00')
	ser4.close()

	
def PS1_5():
	ser9.open()
	test_area.insert(tk.END,str("-- Going to Remote Mode. \n"))
	ser9.write("SESS01\r".encode())
	ser9.write("SESS01\r".encode())
	test_area.insert(tk.END,str("-- Setting up the voltage to +5.0 Vdc. \n"))
	ser9.write("VOLT00050\r".encode())
	test_area.insert(tk.END,str("-- Closing output switch. \n"))
	ser9.write("SOUT000\r".encode())
	ser9.write("SOUT000\r".encode())
	MEAS_1=ser9.write("GETD\r".encode())
	# 500 ms delay for instrument read
	time.sleep(.5)
	test_area.insert(tk.END,str("-- PS1 reporting: "))	
	test_area.insert(tk.END,(MEAS_1))
	test_area.insert(tk.END,str(" volts\n"))	
	test_area.insert(tk.END,str("-- Connecting DMM to PS1 entering the console.\n"))
	test_area.insert(tk.END,str("-- Everything ok? Please prees Y or N...\n"))
	ser9.close()
	ser4.open()
	ser4.write(b'\x03')
	ser4.write(b'\x03')
	ser4.close()
	test_area.yview(END)

def PS1_15():	
	ser9.open()
	test_area.insert(tk.END,str("-- Going to Remote Mode. \n"))
	ser9.write("SESS01\r".encode())
	ser9.write("SESS01\r".encode())
	test_area.insert(tk.END,str("-- Setting up the voltage to +15.0 Vdc. \n"))
	ser9.write("VOLT00150\r".encode())
	test_area.insert(tk.END,str("-- Closing output switch. \n"))
	ser9.write("SOUT000\r".encode())
	ser9.write("SOUT000\r".encode())
	MEAS_2=ser9.write("GETD\r".encode())
	# 500 ms delay for instrument read
	time.sleep(.5)
	test_area.insert(tk.END,str("-- PS1 reporting: "))	
	test_area.insert(tk.END,(MEAS_2))
	test_area.insert(tk.END,str(" volts\n"))	
	test_area.insert(tk.END,str("-- Connecting DMM to PS1 entering the console.\n"))
	test_area.insert(tk.END,str("-- Everything ok? Please prees Y or N...\n"))
	ser9.close()
	ser4.open()
	ser4.write(b'\x03')
	ser4.write(b'\x03')
	ser4.close()
	test_area.yview(END)

def PS1_25():	
	ser9.open()
	test_area.insert(tk.END,str("-- Going to Remote Mode. \n"))
	ser9.write("SESS01\r".encode())
	ser9.write("SESS01\r".encode())
	test_area.insert(tk.END,str("-- Setting up the voltage to +28.0 Vdc. \n"))
	ser9.write("VOLT00280\r".encode())
	test_area.insert(tk.END,str("-- Closing output switch. \n"))
	ser9.write("SOUT000\r".encode())
	ser9.write("SOUT000\r".encode())
	MEAS_3=ser9.write("GETD\r".encode())
	# 500 ms delay for instrument read
	time.sleep(.5)
	test_area.insert(tk.END,str("-- PS1 reporting: "))	
	test_area.insert(tk.END,(MEAS_3))
	test_area.insert(tk.END,str(" volts\n"))	
	test_area.insert(tk.END,str("-- Connecting DMM to PS1 entering the console.\n"))
	test_area.insert(tk.END,str("-- Everything ok? Please prees Y or N...\n"))
	ser9.close()
	ser4.open()
	ser4.write(b'\x03')
	ser4.write(b'\x03')
	ser4.close()
	test_area.yview(END)
	
def PS1_OUT():	
	ser9.open()
	test_area.insert(tk.END,str("-- Going to Remote Mode. \n"))
	ser9.write("SESS01\r".encode())
	ser9.write("SESS01\r".encode())
	test_area.insert(tk.END,str("-- Setting up the voltage to +28.0 Vdc. \n"))
	ser9.write("VOLT00100\r".encode())
	test_area.insert(tk.END,str("-- Closing output switch. \n"))
	ser9.write("SOUT000\r".encode())
	ser9.write("SOUT000\r".encode())
	MEAS_3=ser9.write("GETD\r".encode())
	# 500 ms delay for instrument read
	time.sleep(.5)
	test_area.insert(tk.END,str("-- PS1 reporting: "))	
	test_area.insert(tk.END,(MEAS_3))
	test_area.insert(tk.END,str(" volts\n"))	
	test_area.insert(tk.END,str("-- Connecting DMM to ADAPTER.\n"))
	test_area.insert(tk.END,str("-- Everything ok? Please prees Y or N...\n"))
	ser9.close()
	ser4.open()
	ser4.write(b'\x0B')
	ser4.write(b'\x0B')
	ser4.close()
	test_area.yview(END)
		
def update_blue():
    mylabel.configure(fg = "blue", text = "This is some blue text")
    mylabel.pack(pady = 5)
    
def update_red():
    mylabel.configure(fg = "red", text = "This is some red text")
    mylabel.pack(pady = 5)

def leaving():
	ser9.open()
	ser9.write("VOLT00000\r".encode())
	ser9.write("SOUT000\r".encode())
	ser9.write("SOUT001\r".encode())
	ser9.close()
	#ser10.open()
	#ser10.write("VOLT00000\r".encode())
	#ser10.write("SOUT000\r".encode())
	#ser10.write("SOUT001\r".encode())
	#ser10.close()
	ser4.open()
	ser4.write(b'\x00')
	ser4.close()
	root.destroy()
	#Instruments.devices()
		 
root = Tk()
root.geometry('1000x950+450+70')
root.title("AC/DC Power Supplies Verification Procedure")
root.resizable(False, False)
root.attributes('-topmost', 1)	#always on top
root.protocol("WM_DELETE_WINDOW", on_closing)	
root.focus_set()

#Initializing and opening serial ports
ser4=serial.Serial(port='COM4', baudrate=9600, timeout=1)
ser9=serial.Serial(port='COM9', baudrate=9600, timeout=1)
ser9.close()
ser4.close()


# Title Label
tk.Label(root, 
         text = "ScrolledText Widget Example", 
         font = ("Arial", 15), 
         background = 'lightgray', 
         foreground = "white").grid(column = 0,
                                    row = 0)
			
test_area = scrolledtext.ScrolledText(root, 
                                      wrap = tk.WORD, 
                                      width = 100, 
                                      height = 20, 
                                      font = ("Arial",
                                              12))

test_area.grid(column = 0, pady = 10, padx = 10)
	
Button(root, text='Close',font = ('Arial', 12, "bold"), command = leaving).grid(pady = 10, padx = 10)	
	
test_area.insert(tk.END,("======================================================================\n"))
test_area.insert(tk.END,("P.N: BK Precision 1697        \n"))
test_area.insert(tk.END,("AC/DC Power Supplies Verification Procedure                           \n"))
test_area.insert(tk.END,("Verification Procedure Ver 1.0\n"))
test_area.insert(tk.END,("======================================================================\n"))
test_area.insert(tk.END,("DC Power Supply No.1                                                  \n"))
test_area.insert(tk.END,("COM9 will be open to get access to PS.1 and set voltages... \n"))
test_area.insert(tk.END,("COM4 will be used to connect DMM to read voltages.\n"))

mylabel = Label(root, text = "This is some black text")

#test_area.after(0, PS1_5)
#test_area.after(2000, Ready)
#test_area.after(4000, PS1_15)
#test_area.after(6000, Ready)
#test_area.after(8000, PS1_25)
#test_area.after(10000, Ready)
#test_area.after(12000, PS1_OUT)
#test_area.after(14000, Ready)

#PS1_5
ser9.open()
test_area.insert(tk.END,str("-- Going to Remote Mode. \n"))
ser9.write("SESS01\r".encode())
ser9.write("SESS01\r".encode())
test_area.insert(tk.END,str("-- Setting up the voltage to +5.0 Vdc. \n"))
ser9.write("VOLT00050\r".encode())
test_area.insert(tk.END,str("-- Closing output switch. \n"))
ser9.write("SOUT000\r".encode())
ser9.write("SOUT000\r".encode())
MEAS_1=ser9.write("GETD\r".encode())
# 500 ms delay for instrument read
time.sleep(.5)
test_area.insert(tk.END,str("-- PS1 reporting: "))	
test_area.insert(tk.END,(MEAS_1))
test_area.insert(tk.END,str(" volts\n"))	
test_area.insert(tk.END,str("-- Connecting DMM to PS1 entering the console.\n"))
test_area.insert(tk.END,str("-- Everything ok? Please prees Y or N...\n"))
ser9.close()
ser4.open()
ser4.write(b'\x03')
ser4.write(b'\x03')
ser4.close()
test_area.yview(END)
#ready
keyboard.wait('y'or 'Y')
ser4.open()
ser4.write(b'\x00')
ser4.write(b'\x00')
ser4.close()

ser9.open()
test_area.insert(tk.END,str("-- Going to Remote Mode. \n"))
ser9.write("SESS01\r".encode())
ser9.write("SESS01\r".encode())
test_area.insert(tk.END,str("-- Setting up the voltage to +10.0 Vdc external. \n"))
ser9.write("VOLT00100\r".encode())
test_area.insert(tk.END,str("-- Closing output switch. \n"))
ser9.write("SOUT000\r".encode())
ser9.write("SOUT000\r".encode())
MEAS_3=ser9.write("GETD\r".encode())
# 500 ms delay for instrument read
time.sleep(.5)
test_area.insert(tk.END,str("-- PS1 reporting: "))	
test_area.insert(tk.END,(MEAS_3))
test_area.insert(tk.END,str(" volts\n"))	
test_area.insert(tk.END,str("-- Connecting DMM to ADAPTER.\n"))
test_area.insert(tk.END,str("-- Everything ok? Please prees Y or N...\n"))
ser9.close()
ser4.open()
ser4.write(b'\x0B')
ser4.write(b'\x0B')
ser4.close()
test_area.yview(END)
#ready
keyboard.wait('y'or 'Y')
ser4.open()
ser4.write(b'\x00')
ser4.write(b'\x00')
ser4.close()

root.mainloop()
Larz60+ write Mar-23-2023, 11:38 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply


Messages In This Thread
tkinter - by juliolop - Sep-11-2020, 12:28 PM
RE: tkinter - by Larz60+ - Sep-11-2020, 04:41 PM
RE: tkinter - by juliolop - Sep-15-2020, 12:32 PM
RE: tkinter - by juliolop - Sep-14-2020, 07:54 PM
RE: tkinter - by Larz60+ - Sep-15-2020, 02:49 PM
RE: tkinter - by Knight18 - Sep-15-2020, 03:38 PM
RE: tkinter - by juliolop - Sep-16-2020, 01:59 PM
RE: tkinter - by juliolop - Sep-16-2020, 07:26 PM
RE: tkinter - by deanhystad - Sep-16-2020, 06:23 PM
RE: tkinter - by juliolop - Sep-16-2020, 06:37 PM
RE: tkinter - by deanhystad - Sep-16-2020, 06:53 PM
RE: tkinter - by deanhystad - Sep-17-2020, 05:06 PM
RE: tkinter - by juliolop - Sep-23-2020, 06:24 PM
RE: tkinter - by juliolop - Mar-22-2023, 07:40 PM
RE: tkinter - by deanhystad - Mar-24-2023, 03:25 AM
RE: tkinter - by juliolop - Apr-05-2023, 04:51 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020