![]() |
[Tkinter] Gui creation - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Gui creation (/thread-11072.html) |
Gui creation - Gangadhararao - Jun-21-2018 from tkinter import * import subprocess import os import turtle from tkinter.ttk import * screen = turtle.Screen() try: import tkinter as tk # python v3 except: import Tkinter as tk # python v2 # This function is called when the submit button is clicked def submit_callback(input_entry): print("User entered : " + input_entry.get()) cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") #os.system("cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer") #os.system("serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM3 -b 9600 -v & pause") return None ####################### GUI ########################### root = tk.Tk() root.geometry('800x550') #Set window size # Heading #heading = tk.Label(root, text="BBS",bg="black", fg="orange" ,font=("Times New Roman", 50)) #heading.place(x = 350, y = 0) #lbl = Label(window, text="MAIN MENU", bg="white", fg="orange" ,font=("Times New Roman", 50)) input_label = tk.Label(root, text="Firmware Downloading to \n TMS320F2833x", bg="white", fg="blue" ,font=("Times New Roman", 20)) input_label.place(x = 0, y = 150) input_entry = tk.Entry(root,bg="white", fg="green" ,font=("Times New Roman", 20)) input_entry.place(x = 400, y = 175) screen = turtle.Screen() screen.bgpic(r"C:\ti\c2000\C2000Ware_1_00_04_00\utilities\flash_programmers\serial_flash_programmer\bbs.gif") submit_button = tk.Button(root, text = "Submit", bg="brown", fg="green" ,font=("Times New Roman", 20),command = lambda: submit_callback(input_entry)) submit_button.place(x = 350, y = 450) root.mainloop()-------------------- Hi This is Gangadhararao,am new to python,when am running this code it will displaying image on another screen,i want to display the image in the same window,like in heading it has to display,but it was not coming,am struggling from past 3 days,please kindly help me to solve this Am waiting for your kind help, Thanks & Regards Gangadhararao G [email protected] RE: Gui creation - Gangadhararao - Jun-21-2018 from tkinter import * import subprocess import os import turtle from tkinter.ttk import * screen = turtle.Screen() try: import tkinter as tk # python v3 except: import Tkinter as tk # python v2 # This function is called when the submit button is clicked def submit_callback(input_entry): print("User entered : " + input_entry.get()) cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") #os.system("cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer") #os.system("serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM3 -b 9600 -v & pause") return None ####################### GUI ########################### root = tk.Tk() root.geometry('800x550') #Set window size # Heading #heading = tk.Label(root, text="BBS",bg="black", fg="orange" ,font=("Times New Roman", 50)) #heading.place(x = 350, y = 0) #lbl = Label(window, text="MAIN MENU", bg="white", fg="orange" ,font=("Times New Roman", 50)) input_label = tk.Label(root, text="Firmware Downloading to \n TMS320F2833x", bg="white", fg="blue" ,font=("Times New Roman", 20)) input_label.place(x = 0, y = 150) input_entry = tk.Entry(root,bg="white", fg="green" ,font=("Times New Roman", 20)) input_entry.place(x = 400, y = 175) screen = turtle.Screen() screen.bgpic(r"C:\ti\c2000\C2000Ware_1_00_04_00\utilities\flash_programmers\serial_flash_programmer\bbs.gif") submit_button = tk.Button(root, text = "Submit", bg="brown", fg="green" ,font=("Times New Roman", 20),command = lambda: submit_callback(input_entry)) submit_button.place(x = 350, y = 450) root.mainloop()-------------------- Hi This is Gangadhararao,am new to python,when am running this code it will displaying image on another screen,i want to display the image in the same window,like in heading it has to come,but it was not coming,am struggling from past 3 days,please kindly help me to solve this Am waiting for your kind help, Thanks & Regards Gangadhararao G [email protected] RE: Gui creation - wuf - Jun-21-2018 Hi Gangadhararao One question? For what do you need the turtle module in your application? wuf ;-) RE: Gui creation - Gangadhararao - Jun-21-2018 Hi wuf, Thank you replying,actually in my python code ,iam inserting image means it was showing error like either i need to install PIL or any other.exe files for supporting images,but here by using turtle i can able to insert image and it is not asking any packages,my code also running,but here i have used screen(),that's why i think it was displaying image in other window,but i need to display my image in the same window,please give any idea Iam waiting for your kind reply Thanks & Regards Gangadhararao G RE: Gui creation - wuf - Jun-21-2018 Hi Gangadhararao Here my test script. It is absolutly not optimized. I just tried to interpret your script to create the following test script. I tested it with Ubuntu 18.04, Tkinter Tk8.6, Python 3.5. For images in the .jpg-format the PIL-Module is needed!: import os from functools import partial import subprocess import tkinter as tk APP_TITLE = "Image Display" APP_XPOS = 100 APP_YPOS = 100 APP_WIDTH = 350 APP_HEIGHT = 200 class Application(tk.Frame): def __init__(self, master): self.master = master tk.Frame.__init__(self, master) self.build() def build(self): # Heading self.heading = tk.Label(self, text="BBS", bg="black", fg="orange" , font=("Times New Roman", 50)) self.heading.pack() #place(x = 350, y = 0) self.label = tk.Label(self, text="MAIN MENU", bg="white", fg="orange", font=("Times New Roman", 50)) self.label.pack() # Your image with path self.image = tk.PhotoImage(file=r"C:\ti\c2000\C2000Ware_1_00_04_00\utilities\flash_programmers\serial_flash_programmer\bbs.gif") # My test image #self.image = tk.PhotoImage(file="image.gif") self.image_width = self.image.width() self.image_height = self.image.height() self.canvas = tk.Canvas(self, width=self.image_width, height=self.image_height) self.canvas.pack() self.canvas.create_image(0, 0, anchor='nw', image=self.image) self.control_frame = tk.Frame(self) self.control_frame.pack() input_label = tk.Label(self.control_frame, text="Firmware Downloading to \n TMS320F2833x", bg="white", fg="blue" ,font=("Times New Roman", 20)) input_label.grid(row=0, column=0) input_entry = tk.Entry(self.control_frame, bg="white", fg="green", font=("Times New Roman", 20)) input_entry.grid(row=1, column=0) input_entry.focus_set() submit_button = tk.Button(self.control_frame, text = "Submit", bg="brown", fg="yellow", font=("Times New Roman", 20), command=partial(self.submit_callback , input_entry)) submit_button.grid(row=2, column=0) def submit_callback(self, input_entry): print("User entered : " + input_entry.get()) return cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") os.system("cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer") os.system("serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM3 -b 9600 -v & pause") def main(): app_win = tk.Tk() app_win.title(APP_TITLE) app_win.geometry("+{}+{}".format(APP_XPOS, APP_YPOS)) #app_win.geometry("{}x{}".format(APP_WIDTH, APP_HEIGHT)) app = Application(app_win) app.pack(fill='both', expand=True) app_win.mainloop() if __name__ == '__main__': main()wuf ;-) RE: Gui creation - Gangadhararao - Jun-26-2018 Hi Wuf, Thanks for your support,below is my command line. cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") In the above command, 1) How to change the .ioo file, if we need to browse another file while compiling as it is taking it directly as command and gives no other way to change it while compiling. 2) How to change the Comport (COM7) value, if the hardware is detected at different port while compiling. Note: Need to change the values while compiling. below is my python code #import image from tkinter import * import tkinter.filedialog import sys import glob import serial import serial.tools.list_ports import subprocess from tkinter.ttk import * try: import tkinter as tk # python v3 except: import Tkinter as tk # python v2 # This function is called when the submit button is clicked def submit_callback(input_entry): print("User entered : " + input_entry.get()) cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") #os.system("cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer") #os.system("serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM3 -b 9600 -v & pause") return None # This function is called when the Port button is clicked def port_callback(input_entry1): print("User entered : " + input_entry1.get()) return None #Serial Ports ports = list(serial.tools.list_ports.comports()) for p in ports: print(p) #Browse Button if sys.version_info[0] < 3: import Tkinter as Tk else: import tkinter as Tk def browse_file(): fname = tkinter.filedialog.askopenfilename(filetypes = (("Python files", "*.py"),("Python files", "*.pyw"), ("All files", "*"))) bpath = print (fname) ####################### GUI ########################### root = tk.Tk() root.geometry('800x550') #Set window size # Heading heading = tk.Label(root, text="BBs" ,bg="black", fg="orange" ,font=("Times New Roman", 50)) heading.place(x = 330, y = 0) input_entry = tk.Entry(root,bg="white", fg="green" ,font=("Times New Roman", 12)) input_entry.place(x = 255, y = 125) portButton = Tk.Button(root, text = 'Port', width = 12, command = lambda: port_callback(input_entry1)) portButton.place(x= 435,y= 125) input_label = tk.Label(root, text="Firmware Downloading to \n TMS320F2833x", bg="white", fg="blue" ,font=("Times New Roman", 20)) input_label.place(x = 248, y = 185) broButton = Tk.Button(root, text = 'Browse', width = 12, command=browse_file) broButton.place(x= 435,y= 300) input_entry1 = tk.Entry(root,bg="white", fg="green" ,font=("Times New Roman", 12)) input_entry1.place(x = 255, y = 300) submit_button = tk.Button(root, text = "Submit", bg="brown", fg="green" ,font=("Times New Roman", 20),command = lambda: submit_callback(input_entry)) submit_button.place(x = 350, y = 450) Tk.mainloop()Iam waiting for your kind reply, Thanks & Regards Gangadhararao G Command line with python - Gangadhararao - Jun-26-2018 Hi , Actually am new to python ,below is my command line. cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") In the above command, 1) How to change the .ioo file, if we need to browse another file while compiling as it is taking it directly as command and gives no other way to change it while compiling. 2) How to change the Comport (COM7) value, if the hardware is detected at different port while compiling. Note: Need to change the values while compiling. below is my python code #import image from tkinter import * import tkinter.filedialog import sys import glob import serial import serial.tools.list_ports import subprocess from tkinter.ttk import * try: import tkinter as tk # python v3 except: import Tkinter as tk # python v2 # This function is called when the submit button is clicked def submit_callback(input_entry): print("User entered : " + input_entry.get()) cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM7 -b 9600 -v") #os.system("cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer") #os.system("serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a PQCR.i00 -p COM3 -b 9600 -v & pause") return None # This function is called when the Port button is clicked def port_callback(input_entry1): print("User entered : " + input_entry1.get()) return None #Serial Ports ports = list(serial.tools.list_ports.comports()) for p in ports: print(p) #Browse Button if sys.version_info[0] < 3: import Tkinter as Tk else: import tkinter as Tk def browse_file(): fname = tkinter.filedialog.askopenfilename(filetypes = (("Python files", "*.py"),("Python files", "*.pyw"), ("All files", "*"))) bpath = print (fname) ####################### GUI ########################### root = tk.Tk() root.geometry('800x550') #Set window size # Heading heading = tk.Label(root, text="BBs" ,bg="black", fg="orange" ,font=("Times New Roman", 50)) heading.place(x = 330, y = 0) input_entry = tk.Entry(root,bg="white", fg="green" ,font=("Times New Roman", 12)) input_entry.place(x = 255, y = 125) portButton = Tk.Button(root, text = 'Port', width = 12, command = lambda: port_callback(input_entry1)) portButton.place(x= 435,y= 125) input_label = tk.Label(root, text="Firmware Downloading to \n TMS320F2833x", bg="white", fg="blue" ,font=("Times New Roman", 20)) input_label.place(x = 248, y = 185) broButton = Tk.Button(root, text = 'Browse', width = 12, command=browse_file) broButton.place(x= 435,y= 300) input_entry1 = tk.Entry(root,bg="white", fg="green" ,font=("Times New Roman", 12)) input_entry1.place(x = 255, y = 300) submit_button = tk.Button(root, text = "Submit", bg="brown", fg="green" ,font=("Times New Roman", 20),command = lambda: submit_callback(input_entry)) submit_button.place(x = 350, y = 450) Tk.mainloop() Iam waiting for your kind reply, Thanks & Regards Gangadhararao G RE: Gui creation - wuf - Jun-26-2018 Hi Gangadhararao My question. Why did'nt not you place your code in Python code tags as you did in your first threads? The code is otherwise very difficult to read and causes headaches. wuf ;-) RE: Gui creation - wuf - Jun-26-2018 Hi Gangadhararao Try out the following lines: my_i00_file = input_entry.get() # In your exsample = PQCR.i00 my_com_port = input_entry.get() # In your exsample = COM7 cmd = subprocess.Popen("cmd.exe /K cd C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe -d f2803x -k f28335_flash_kernel.txt -a {} -p {} -b 9600 -v".format(my_i00_file, my_com_port))P.S. Thanks Larz60+ for your support! wuf ;-) RE: Gui creation - snippsat - Jun-27-2018 cd will work in a subprocess call.There is a cwd parameter that change directory.Also if pass commands as a string most have shell=True .It's better and safer to pass commands a list,then default is shell=False .Example: import subprocess subprocess.run(['-d', 'f2803x', '-k', 'f28335_flash_kernel.txt', '-a', 'PQCR.i00', '-p', 'COM7', '-b', '9600', '-v'], cwd='C:\\ti\\c2000\\C2000Ware_1_00_04_00\\utilities\\flash_programmers\\serial_flash_programmer & serial_flash_programmer.exe') |