# GUI

## January 6, 2021

Site Index

2. Scroll to bottom of page.
• Any posts / pages within this blog will be displayed.

## Y

#YearOfTheFediverse

#Zoo

## December 14, 2020

Xfce4 multiscreen support

As my netbook is running Debian 10 + XFCE 4 desktop then plugging in a vga cable which is attached to my TV gives me the option to use the TV as a display too.

So this gives various options, extending the display will then allow windows to be dragged over, so I can watch a full screen peertube video on the tv for example.

Clicking the advanced option gives you the ability to fine tune this setup

Note Upon plugging in the VGA cable, the screen resolution will change and the dialogue box mentioned above will be displayed, removing the cable should restore the display.

As with anything Your mileage may vary with this*, but it seems to work really well.

This article will be shared via rss and on Mastodon, if you need any help then I will do my best to help with this, but you may want to follow XFCE on Mastodon

## May 19, 2020

More improvements

So last time we added some text boxes and made the application a little more presentable. Now we are going to do is add some labels above the boxes to help describe what they do.

Add this above were we define the entry boxes

# define some labels
box1 = Label(window, text="Entry 1: ")
box2 = Label(window, text="Entry 2: ")
box3 = Label(window, text="Ouput1: ")



Now add this below where we place the entry boxes but above window.mainloop()

#place labels
box1.grid(row = 1	, column = 2, padx = 5, pady = 5)
box2.grid(row = 1	, column = 3, padx = 5, pady = 5)
box3.grid(row = 1	, column = 4, padx = 5, pady = 5)


So here we have a window, with three text boxes.

So again we have something that looks a little more like an application.

## May 18, 2020

Tidying up our application

So my last post produced something that did not really look very good. So I have now tidied the code up a little bit to make it look better.

So one of the useful things within this is to adjust the dimensions of our application, so everything fits in to the window area nicely, but not leave too much empty space.

#!/usr/bin/env python
import Tkinter # note use of caps
from Tkinter import *

window = Tk()
window.title('App 1')
window.geometry("600x50") # w x h
window.resizable(0,0)

#define entry box

entry1 = StringVar() # this is our entry box
entrytext = Entry(window, textvariable=entry1) # this is our entry box
entrytext2 = Entry(window, textvariable=entry1) # this is our second entry box
#define out box

entry2 = StringVar() # this is our output box
outtext1 = Entry(window, textvariable=entry2) # this is our output box

#display boxes
entrytext.grid(row = 3, column = 2,)  #display entry box
entrytext2.grid(row = 3, column = 3,)  #display entry box
outtext1.grid(row = 3, column = 4,) #display output box

window.mainloop()



So here we have a window, with three text boxes.

Which is starting to look a little better. The main bit of advice I can give here, is test, test and test again, that way you know your application is working as you go.

## May 17, 2020

More tkinter : Add entry and text box

This code adds a box to our application, a box can serve either as a text output box OR a text entry box.

Note I have included the whole program here. I have also defined the size of our application.

While the window is bigger and the boxes are at the top, the idea is that it just displays those boxes. We can tidy things up later.

#!/usr/bin/env python
import Tkinter # note use of caps
from Tkinter import *

window = Tk()
window.title('GUI Tkinter 1')
window.geometry("300x250") # w x h
window.resizable(0,0)

#define entry box

circleVar = StringVar()
circletext = Entry(window, textvariable=circleVar)

#define out box

circleVar2 = StringVar()
circletext2 = Entry(window, textvariable=circleVar2)

circleVar2 = StringVar()
circletext2 = Entry(window, textvariable=circleVar2)

#display boxes
circletext.grid(row = 1, column = 2,)
circletext2.grid(row = 2, column = 2,)

window.mainloop()



We get:

## May 16, 2020

More tkinter : Combine buttons and labels.

Now that we can add a label and a button, it is time to combine the two. The following code does this.

#define functions for button(s)
def btn1():
print ("button pressed")

#create button object
btn_tog2 = Button( window, text ='button1', command=btn1)
btn_exit = Button( window, text ='exit',command=exit)

#place button object
btn_tog2.grid(row = 1, column = 2, padx = 5, pady = 5)
btn_exit.grid(row = 2, column = 2, padx = 5, pady = 5)

#define labeles
button1 = Label(window, text="press button")
button2 = Label(window, text="exit program")

#place labels
button1.grid(row = 1, column = 1, padx = 5, pady = 5)
button2.grid(row = 2, column = 1, padx = 5, pady = 5)


We get:

## May 15, 2020

So to carry on with some basic tk development, Once we can add a label, we add buttons. While buttons have a built in label, the label widget could be useful to add more description to that area of the application.

def btn1():
print ("button pressed")

btn_tog2 = Button( window, text ='button1', command=btn1)
btn_exit = Button( window, text ='exit',command=exit)

btn_tog2.grid(row = 1, column = 1, padx = 5, pady = 5)
btn_exit.grid(row = 2, column = 1, padx = 5, pady = 5)


We get:

With this we have added an event, so in this case the btn_tog2 runs the function btn1 which prints “button pressed” to the console.

## May 14, 2020

More tkinter development

So further to yesterdays post

The next step is to add some widgets to our application. It is generally useful to label any items. That way a user knows what purpose an entry box has.

If we take the code block from yesterday and add

#define labeles
box1 = Label(window, text="Entry 1: ")

#place labels
box1.grid(row = 1, column = 1, padx = 5, pady = 5)


before the window.mainloop() statement.

We get:

## May 13, 2020

Tkinter Development

A few years ago, I created a resource to explain how to create use some of the widgets within tkinter. This is a Python widget for creating graphical user interfaces (GUIs).

The following code is what you need to get started. This creates, just a single application window.

#!/usr/bin/env python
import Tkinter # note use of caps
from Tkinter import *

window = Tk()
window.title('GUI Tkinter 1')
window.geometry("300x250") # w x h
window.resizable(0,0)

window.mainloop()


This produces

Over the next few days, I will make more posts covering adding labels, buttons and entry / text boxes.

Hopefully it will be of use to someone.

## March 22, 2020

FreeBSD 7

Further to my previous post I have been on IRC #freebsd in order to ask about what would be good to use for taking screen shots of desktop applications for example.

Scrot : is easy to use and you cam use this to take a picture of the whole screen, this will be useful going forward with these posts.

pkg install scrot

For basic usage just type scrot at the console or in a terminal window.

I have also installed simpleviewer, with

pkg install simpleviewer

However running this at the cli did do anything, you need to find the actual binary executable for this.

info -lx simpleviewer

reveals sviewgl as the program you need to run.

I am now pretty much set up for taking screenshots and being able to view then.

Resources

You can find me on Friendica at zleap@social.isurf.ca

Licenced under Attribution 4.0 International (CC BY 4.0)