Welcome back to the same project which I have created earlier, I have decided to continue posting articles about this project instead of just develop it behinds the scene, after all, code sharing is what readers love to read so why not?
In this article, I will create two radio buttons to replace the previous combo box which will let the user selects either one of the colors. I will also create two label frames to hold the submit section as well as the search section. Another frame will be used to hold the radio buttons.
Only the UI part of this project has been modified and the entire updated file is as follows:-
import tkinter as tk from tkinter import ttk from data import Data from tkinter import messagebox def subMit(): radSelect = color.get() color_select = '' if radSelect == 1: color_select = "Red" elif radSelect == 2: color_select = "Green" submit.submit(entry.get(), color_select, entry1.get(), entry2.get()) def search(): submit.search(entry3.get(), messagebox) win = tk.Tk() win.title('STData') win.resizable(0,0) entryFrame = ttk.Labelframe(win, text="Submit Data") entryFrame.grid(column=0, row=0, padx=10,pady=10) # symbol text box entry = tk.StringVar(entryFrame, value='symbol') entry_txt = ttk.Entry(entryFrame, width=12, textvariable=entry) entry_txt.grid(column=0, row=0) entry_txt.focus() # type text box entry1 = tk.StringVar(entryFrame, value='type') entry_txt1 = ttk.Entry(entryFrame, width=12, textvariable=entry1) entry_txt1.grid(column=1, row=0) # price text box entry2 = tk.StringVar(entryFrame, value='unit price') entry_txt2 = ttk.Entry(entryFrame, width=12, textvariable=entry2) entry_txt2.grid(column=2, row=0) radio1Frame = ttk.Frame(entryFrame) radio1Frame.grid(column=3, row=0, padx=5,pady=3) # select a color in radio button COLOR1 = "RED" COLOR2 = "GREEN" color = tk.IntVar(radio1Frame) color.set(1) #select the first radio button as default color_red = ttk.Radiobutton(radio1Frame, text=COLOR1, variable=color, value=1) color_red.grid(column=0, row=0,sticky=tk.W) color_green = ttk.Radiobutton(radio1Frame, text=COLOR2, variable=color, value=2) color_green.grid(column=0, row=1,sticky=tk.W) ttk.Button(entryFrame, text="Submit", command=subMit).grid(column=4, row=0) searchFrame = ttk.Labelframe(win, text="Search Data") searchFrame.grid(column=0, row=1, padx=10,pady=3) # search text box entry3 = tk.StringVar(searchFrame, value='symbol') entry_txt3 = ttk.Entry(searchFrame, width=12, textvariable=entry3) entry_txt3.grid(column=0, row=0) ttk.Button(searchFrame, text="Search", command=search).grid(column=1, row=0, padx=3) submit = Data() #initialize/create database win.mainloop()
The user interface is now neater as compared to before…
I will continue posting this project as well as other projects at the same time, I am thinking of starting a few projects at the same time on this website!
from Planet Python
via read more
No comments:
Post a Comment