Python Forum
[Tkinter] How to proceed?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to proceed?
#1
The below is my code that works perfect when i post it to python idle and run it.

However i am having difficulty doing the following:

How do it do the following?

#1. add a screen that display the output
#2. The buttons are not scaling to the window frame, and the alignment seem to be out of array.
#tips and tricks and where can i get additional information..

use the attached link or copy and paste the below code to see how it perform in python idle:
https://trinket.io/python/ce006021fe


from tkinter import *
import time;
import tkinter.messagebox


def test():
    print("Test works")


def raise_frame(frame):
    frame.tkraise()

root = Tk()
root.title("MESPOS")
#Minimum size of the window and maximum size




#Menu drop down File Edit

menu = Menu(root)
root.config(menu=menu)
    
subMenu = Menu(menu)
menu.add_cascade(label="File", menu=subMenu)
    #add stuff to drop down
subMenu.add_command(label="New project", command=test)
subMenu.add_command(label="New", command=test)
subMenu.add_separator()
subMenu.add_command(label="exit", command=test)


editMenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editMenu)
editMenu.add_command(label="Redo", command=test)
editMenu.add_separator()
editMenu.add_command(label="Cut", command=test)
editMenu.add_command(label="Paste", command=test)



topFrame = Frame(root)
topFrame.pack(side=TOP, fill=X)
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM, fill=X)
bottomFrame1 = Frame(root)
bottomFrame1.pack(side=BOTTOM, fill=X)

#toolbar
toolbar =Frame(topFrame, bg="skyblue")

localtime=time.asctime(time.localtime(time.time()))

saleb1 = Button(toolbar, text="     Sale     ",
                command= lambda: raise_frame(f1)).pack(side=LEFT, padx=2, pady=2)

    

purb1 = Button(toolbar, text="Purchase",
               command=lambda:raise_frame(f2)).pack(side=LEFT, padx=2, pady=2)

invb1 = Button(toolbar, text="Inventory",
               command=lambda:raise_frame(f3)).pack(side=LEFT, padx=2, pady=2)

timebar = Label(toolbar, text=localtime, fg="steel blue")
timebar.pack(side=RIGHT)

toolbar.grid(row=1, column=0, sticky='news')

#frames    
f1 = Frame(bottomFrame1, bg="RED")
f2 = Frame(bottomFrame1, bg="blue")
f3 = Frame(bottomFrame1, bg="green")
f4 = Frame(bottomFrame1)

for frame in (f1, f2, f3, f4):
    frame.grid(row=0, column=0, sticky='news')

#Sales

#******************PURCHASES******************************* 

Label(f2, text='PURCHASES').pack()


topf2 = Frame(f2)
topf2.pack(side=TOP, fill=X)
bottomf2 = Frame(f2)
bottomf2.pack(side=BOTTOM, fill=Y)


# Search Sales
label_21 = Label(topf2, text="Search" , bg="blue", fg="white")
entry_21 = Entry(topf2)


label_21.grid(row=2,column=6, sticky=E)
entry_21.grid(row=2,column=5, sticky=E)
    #sticky right alighn the word.

Button(bottomf2, text='Go to frame 3', command=lambda:raise_frame(f3)).pack()

#*********************INVENTORY**********************
Label(f3, text='INVENTORY 3').pack()
Button(f3, text='Go to frame 4', command=lambda:raise_frame(f4)).pack(side='left')





topf3 = Frame(f3)
topf3.pack(side=TOP, fill=X)
bottomf3 = Frame(f3)
bottomf3.pack(side=BOTTOM, fill=Y)


# Search Sales
label_31 = Label(topf3, text="Search" , bg="blue", fg="white")
entry_31 = Entry(topf3)


label_31.grid(row=2,column=4, sticky=E)
entry_31.grid(row=2,column=3, sticky=E)
    #sticky right alighn the word.


#********************************************

Label(f4, text='FRAME 4').pack()
Button(f4, text='Goto to frame 1', command=lambda:raise_frame(f1)).pack()

toolbar.pack(side=TOP, fill=X)
#******************* Sales *******************************

#canvas




#label
theLabel =Label(f1, text="Sales")
theLabel.pack()

topf1 = Frame(f1)
topf1.pack(side=TOP, fill=X)
bottomf1 = Frame(f1)

#testing
sigh =Label(bottomf1, text="SCREEN", bg="GREY", height="15", width="40")
sigh.pack(side=LEFT, fill=X)



bottomf1.pack(side=TOP, fill=Y)
bottomf1b = Frame(f1)
bottomf1b.pack(side=TOP, fill=Y)

# Search Sales
label_1 = Label(topf1, text="Search" , bg="blue", fg="white")
entry_1 = Entry(topf1)


label_1.grid(row=2,column=4, sticky=E)
entry_1.grid(row=2,column=3, sticky=E)
    #sticky right alighn the word.

#Check box
check = Checkbutton(topf1, text="Taxable")
check.grid(columnspan=1)
 
 # cash button
button1 = Button(bottomf1b, text="Cash",  width=10, height=1, fg="red", command=test)
button1.pack(side=LEFT)

# cheque button
button2 = Button(bottomf1b, text="CHEQUE", width=10, height=1, fg="skyblue")
button2.pack(side=LEFT)

# Card button
button3 = Button(bottomf1b, text="CARD", width=10, height=1, fg="green")
button3.pack(side=LEFT, fill=X)
    

Button(bottomf1b, text='Go to frame 2', command=lambda:raise_frame(f2)).pack()
Label(f1, text='FRAME 1').pack(fill=X)

#*************Status bar*******************
status = Label(bottomFrame, text="connected", bd=1, relief=SUNKEN, anchor=W)
status.pack(side=BOTTOM, fill=X)


raise_frame(f1)
Reply
#2
to display text, use a Text widget.
this widget class has built in methods that can be used to
do all sorts of things that you might see in something like MS word.
For very simple text entry, there is the insert method:
.insert(index, text, tags=None)
for a list of what's available, see: http://infohost.nmt.edu/tcc/help/pubs/tk...thods.html
for everything else associated with this widget, see: http://infohost.nmt.edu/tcc/help/pubs/tk...indow.html
Reply
#3
(Feb-25-2018, 05:49 AM)Larz60+ Wrote: to display text, use a Text widget.
this widget class has built in methods that can be used to
do all sorts of things that you might see in something like MS word.
For very simple text entry, there is the insert method:
.insert(index, text, tags=None)
for a list of what's available, see: http://infohost.nmt.edu/tcc/help/pubs/tk...thods.html
for everything else associated with this widget, see: http://infohost.nmt.edu/tcc/help/pubs/tk...indow.html

If you run the code, you would see my intention.. I have done a screen that is the output screen, but am not sure how to do out put in the screen

In addition the frames are not scaling to the main frame. Hence when i extend the frame up or outwards the buttons and the frames align right and there is this huge space.
Reply
#4
Quote:I have done a screen that is the output screen, but am not sure how to do out put in the screen
You have label with the text "Screen" that is never referenced in any way other than to create it. Is this your screen widget or is something else? Docs on the label widget if it is http://effbot.org/tkinterbook/label.htm

Use row & columnconfigure to allow the widgets to move when the frame is resized http://effbot.org/tkinterbook/widget.htm A simple example below as I don't want to wade through 100 lines of code with no documentation other than "cash button" for a button with the text "cash button", and no functions or anything else to split it up into meaningful chunks, and then have you tell me to run the code, which tells me less than than the code itself.

import tkinter

root = tkinter.Tk()
root.geometry("750x500")

## use a frame to set a smaller dimension
main=tkinter.Frame(root, height=100)
main.grid(row=0, column=0)
root.rowconfigure(0, weight=1, minsize=50)
root.columnconfigure(0, weight=2, minsize=500)

ml1 = tkinter.Label(main, text ="Label Widget", bg="lightblue", width=30)
ml1.grid(row=0, column=0, sticky="nesw")
main.rowconfigure(0, weight=1, minsize=50)
main.columnconfigure(0, weight=2, minsize=500)

tkinter.Button(root, text="Exit", command=root.quit, bg="orange").grid(row=900, column=0)
root.mainloop() 
Reply
#5
you need to add:
root.mainloop()
as last line
Alignment is a nightmare in tkinter. That's the main reason why I refrain from using it anymore.
Unless it's my own code, I don't want to go there, only suggest changing GUI's
Reply


Forum Jump:

User Panel Messages

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