Window sizing

28 views
Skip to first unread message

John Boyd

unread,
Oct 23, 2018, 8:53:25 PM10/23/18
to Kivy users support
Hello,

I wrote the following script which has two textinputs in a vertical boxlayout.  I am trying to set app window only large enough to contain the textinputs.

import kivy
kivy
.require('1.10.1')


from kivy.core.window import Window


from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput


mainframe
= BoxLayout(orientation='vertical',
                      size_hint
=(None, None),
                      size
=(200,200))
tablename
= TextInput(multiline = False)
fieldname
= TextInput(multiline = False)


mainframe
.add_widget(tablename)
mainframe
.add_widget(fieldname)


class Test(App):
   
def build(self):
       
return mainframe
   
Window.fullscreen = False
Test().run()

Unfortunately I am unable to change the size of the apps window. 
I tried at the top of the script :
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')

And I tried :
Window.size = (200,200)

just before the Test().run() command.

Nothing works.

Any help will be appreciated.

Best Regards,
John.

NOTE: Running Kivy 1.10.1 in a virtualenv on Ubuntu 18.04.1 LTS.

srinivas sagit

unread,
Oct 23, 2018, 9:45:04 PM10/23/18
to kivy-...@googlegroups.com
https://stackoverflow.com/questions/14014955/kivy-how-to-change-window-size
This link help you! I'm also struggled in this error!

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6714f110-cc1e-4022-bb60-5346314b40b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Boyd

unread,
Oct 23, 2018, 10:00:47 PM10/23/18
to Kivy users support
Hello Srinavas,

Thanks for the reply, unfortunately I tried both suggestions in the link and none worked. 
In my search I did find that link before posting here.

Best Regards,
John.

J34n

unread,
Oct 24, 2018, 2:09:07 AM10/24/18
to Kivy users support
Hello,

You have to configure the graphics before you import the Window class, because when you do, the size of the window is reset.

Something like this:

import kivy
kivy.require('1.10.1')

from kivy.config import Config 
Config.set('graphics', 'width', '200') 
Config.set('graphics', 'height', '200')

from kivy.core.window import Window

# Remaining code…

Regards.

John Boyd

unread,
Oct 24, 2018, 4:29:02 PM10/24/18
to Kivy users support
Hi J34n,

That was one of the first things I tried. However I finally got it to work by doing the following:

# Set up the required Window size.
from kivy.config import Config
Config.set('graphics', 'window_state', 'visible')
from kivy.core.window import Window
Window.fullscreen = 1
Window.size = (200,60)

And the final full script:

import kivy
kivy
.require('1.10.1')


# Set up the required Window size.
from kivy.config import Config
Config.set('graphics', 'window_state', 'visible')
from kivy.core.window import Window
Window.fullscreen = 1
Window.size = (200,60)



from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput


#from kivy.core.window import Window



mainframe
= BoxLayout(orientation='vertical',
                      size_hint
=(None, None),

                      size
=(200,60))

tablename
= TextInput(multiline = False)
fieldname
= TextInput(multiline = False)


mainframe
.add_widget(tablename)
mainframe
.add_widget(fieldname)


class Test(App):
   
def build(self):
       
return mainframe
   


Test().run()

The window opens to the top left corner so I now have to figure out how to get it to the center of the screen.

Thanks for the help and feedback.

srinivas sagit

unread,
Oct 24, 2018, 11:50:03 PM10/24/18
to kivy-...@googlegroups.com
Set the window size to textinput size bro

John Boyd

unread,
Oct 25, 2018, 11:20:45 AM10/25/18
to Kivy users support
Hi all,

Issue solved, I realized my default config.ini was different from standard install. So I reinstalled kivy, and now these three lines at the top works
and the window is centered in the screen:

from kivy.config import Config
Config.set('graphics', 'width',200)
Config.set('graphics', 'height',60)

Thanks again.
Reply all
Reply to author
Forward
0 new messages