Hello!
I am new to Python, and I want to learn it.
I have just installed Python 2.7.3
And Visual Python Tkinter IDE for Ver 2.6-2.7-3.1 (BETA) –Version: 2.0.12.2524.

I was looking into some the Tutorial and follow the first example to code.
Here begun my issues.

First Step:
I created a simple Window application with nothing on it.
Run it with no problem.

Second step:
Add a Button, Text, Label, etc to the design Form
Run it, and here is my first problem. The window opens like the first time with nothing in it. I don see the button or anything. In addition, I have tried to delete the label or button hitting the delete key but it does not removed from the Design form. I can add resize but no delete.
Any help is appreciated,
Thanks in advance

Recommended Answers

All 6 Replies

What layout manager are you using?

For instance the grid layout manager:

# looking at the Tkinter grid() layout manager
#
# The size of a grid cell in a given row or column is
# determined by its largest widget.
#
# If you give a grid layout more space than it needs,
# it will fill this space from its center on out.
# A way around this is to use place() with a frame and
# then grid() within this frame.
#
# Grid does not have an anchor positioner like pack().
#
# You can use place() and grid(), but not pack() and grid()
# within the same container widget.
#
# You can put a child grid into a parent grid.

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()
root.title('Grid layout')
root['bg'] = 'yellow'

b1 = tk.Button(root, text="Button1")
b2 = tk.Button(root, text="Button2", bg='green')
b3 = tk.Button(root, text="Button3")
b4 = tk.Button(root, text="Button4")
b5 = tk.Button(root, text="Button5")
b6 = tk.Button(root, text="Button6")
b7 = tk.Button(root, text="Button7", bg='blue')
# button b8 has a 3 row text
b8 = tk.Button(root, text="\nButton8\n", bg='red')

b1.grid(row=0, column=1)
# use sticky=tk.E+tk.W or sticky='ew'
b2.grid(row=1, column=0, columnspan=3, sticky='ew')
b3.grid(row=2, column=0, pady=5)
b4.grid(row=2, column=1)
# gives the entire column=2 padx=10 padding!
b5.grid(row=2, column=2, padx=10)
b6.grid(row=3, column=2)
# forces button b7 to take up padded space too
b7.grid(row=4, column=2, ipadx=10)
# button b8 has a 3 row text, so give it rowspan=3
b8.grid(row=5, column=0, rowspan=3, columnspan=3, sticky='ew')

# dictionary of grid info for button b8
print( b8.grid_info() )
# specific info about b8
print( b8.grid_info()['row'] )  # 5

# optional, but interesting
# get the size of the root (root.update is needed!)
root.update()
width = root.winfo_width()  # 158
print(width)
height = root.winfo_height()  # 174
print(height)

root.mainloop()

Or the pack layout manager:

# a general Tkinter program to enter two data items
# process the data and display the result

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def calculate():
    """
    in this case the data items are floating point numbers
    that are simply added in the example data process
    the result is displayed in a label
    """
    try:
        x = float(enter1.get())
        y = float(enter2.get())
        # the process step, customize to your needs ...
        s = str(x + y)
        # display the result
        label3.config(text=s)
    except ValueError:
        label3.config(text='Enter numeric values for x and y')

def setfocus2(event):
    enter2.focus_set()


# create the root window
root = tk.Tk()

# create all the components/widgets
label1 = tk.Label(root, text='Enter number x:', width=28)
enter1 = tk.Entry(root, bg='yellow')
label2 = tk.Label(root, text='Enter number y:')
enter2 = tk.Entry(root, bg='yellow')
button1 = tk.Button(root, text='Add the numbers', command=calculate)
# the result label
label3 = tk.Label(root, text='', bg='green')

# pack widgets vertically in the root window in that order
label1.pack(side='top', fill='x')
enter1.pack(side='top', fill='x')
label2.pack(side='top', fill='x')
enter2.pack(side='top', fill='x')
button1.pack(side='top')
label3.pack(side='top', fill='x')

# cursor in enter1
enter1.focus()
# return key in enter1 sets focus to enter2
enter1.bind("<Return>", func=setfocus2)

# start the event loop
root.mainloop()

This is the code generated after I add to the Design Form

#   Project Name    :   Visual Python IDE for 2.6
#   Date            :   13-12-2009
#   Author          :   macrocoders team
#   Contact         :   macrocoders@gmail.com
#   Web             :   http://visualpython.org
#   Python Ver.     :   2.6

# -*- coding: utf-8 -*-

from Tkinter import *
from tkMessageBox import *
from Sample_py import *

# -- Do not change. You may experience problems with the design file. #
form1=Tk()
form1.title('form1')
form1.resizable(width=FALSE, height=FALSE)
form1.geometry('469x335+100+100')
# -- Do not change. You may experience problems with the design file. #

# -- Do not change. You may experience problems with the design file. -- #
radioButton1=Radiobutton(text='radioButton1', command=radioButton1Click)
radioButton1.place(relx=0., rely=0., relwidth=0., relheight=0.)

# -- Do not change. You may experience problems with the design file. -- #
checkBox1=Checkbutton(text='checkBox1', command=checkBox1Click)
checkBox1.place(relx=0., rely=0., relwidth=0., relheight=0.)

# -- Do not change. You may experience problems with the design file. -- #
richTextBox1=Text(font = '{MS Sans Serif} 10')
richTextBox1.place(relx=0., rely=0., relwidth=0., relheight=0.)

# -- Do not change. You may experience problems with the design file. -- #
textBox1=Entry(font = '{MS Sans Serif} 10')
textBox1.place(relx=0., rely=0., relwidth=0., relheight=0.)

# -- Do not change. You may experience problems with the design file. -- #
label1=Label(text='label1')
label1.place(relx=0., rely=0., relwidth=0., relheight=0.)

# -- Do not change. You may experience problems with the design file. -- #
button1=Button(text='button1', command=button1Click)
button1.place(relx=0., rely=0., relwidth=0., relheight=0.)

form1.mainloop()

The place layout manager is probably the most difficult one to work with. Using relative values makes the widgets stretch proberly when the master is stretched.

Arguments relwidth and relheight are relative to the master the widgts are in. Giving them a value of zero makes them not show up. Possible values are from 0.0 to 1.0
Also anchor positions relx and rely can not all be the same value or the widgets will overlap.

Try something like this ...

#   Project Name    :   Visual Python IDE for 2.6
#   Date            :   13-12-2009
#   Author          :   macrocoders team
#   Contact         :   macrocoders@gmail.com
#   Web             :   http://visualpython.org
#   Python Ver.     :   2.6

# -*- coding: utf-8 -*-

from Tkinter import *
from tkMessageBox import *
#from Sample_py import *

def radioButton1Click():
    pass

def checkBox1Click():
    pass

def button1Click():
    pass

# -- Do not change. You may experience problems with the design file. #
form1=Tk()
form1.title('form1')
form1.resizable(width=FALSE, height=FALSE)
form1.geometry('469x335+100+100')
# -- Do not change. You may experience problems with the design file. #

# -- Do not change. You may experience problems with the design file. -- #
radioButton1=Radiobutton(text='radioButton1', command=radioButton1Click)
radioButton1.place(relx=0., rely=0., relwidth=0.2, relheight=0.1)

# -- Do not change. You may experience problems with the design file. -- #
checkBox1=Checkbutton(text='checkBox1', command=checkBox1Click)
checkBox1.place(relx=0.3, rely=0., relwidth=0.2, relheight=0.1)

# -- Do not change. You may experience problems with the design file. -- #
richTextBox1=Text(font = '{MS Sans Serif} 10')
richTextBox1.place(relx=0., rely=0.1, relwidth=0.2, relheight=0.3)

# -- Do not change. You may experience problems with the design file. -- #
textBox1=Entry(font = '{MS Sans Serif} 10')
textBox1.place(relx=0., rely=0.4, relwidth=0.2, relheight=0.3)

# -- Do not change. You may experience problems with the design file. -- #
label1=Label(text='label1')
label1.place(relx=0., rely=0.75, relwidth=0.1, relheight=0.1)

# -- Do not change. You may experience problems with the design file. -- #
button1=Button(text='button1', command=button1Click)
button1.place(relx=0., rely=0.85, relwidth=0.4, relheight=0.1)

form1.mainloop()

What kind of form designer did you use?

vegaseat,
Thanks for your input.
Yes definitely by giving values to relx and rely will make them show.
However, the buttons, labels, text, etc it supposed to take a value automatically once I add them to the DesignForm.
I am using:
Visual Python Tkinter IDE for Ver 2.6-2.7-3.1 (BETA) –Version: 2.0.12.2524.

Visual Python Tkinter IDE is a very badly written piece of software with lots of errors.
I don't recommend using it unless you want to waste a lot of time.

Thanks for the advice.
Any suggestion on which IDE I can use?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.