How to setup resolution correctly?

Godot Version

4.2.2

Question

So I have a script that changes the game resolution but every time I change it, it always makes the game look wonky. I am new to godot so I do not know how to make the resolution not do this. How exactly do I anchor something correctly.

This is the resolution (windowed) not 1920x1080

Fullscreen not 1920x1080

I recommend you watch this tutorial:
Godotneers - Godot UI Basics - how to build beautiful interfaces that work everywhere (Beginners)

or this one: Game Dev Artisan - Building a UI in Godot - Godot Fundamentals

The first one did exactly what I wanted however, if I select a resolution under 1920x1080 in fullscreen mode it does this

Now I do not know if in the resolution I selected looks ok for if someone had that type of screen but is there a way to fix that or is it normal?

I am running the exact same settings as the tutorial since it worked fine

Can you show us the code you are using to change the resolution?

extends OptionButton

@onready var resolutionBtn = get_node("..//resolutionBtn")
@onready var fullscreenBtn = get_node("..//fullscreenBtn")

var Resolutions: Dictionary = {
	"3840x2160":Vector2i(3840, 2160),
	"2560x1440":Vector2i(2560, 1440),
	"1920x1080":Vector2i(1920, 1080),
	"1366x768":Vector2i(1366, 768),
	"1280x720":Vector2i(1280, 720),
	"1440x900":Vector2i(1440, 900),
	"1024x600":Vector2i(1024, 600),
	"800x600":Vector2i(800, 600)
}

func _ready():
	addResolutions()
	checkVariables()
	
func checkVariables():
	var _window = get_window()
	var mode = _window.get_mode()
	
	if mode == Window.MODE_FULLSCREEN:
		fullscreenBtn.set_pressed_no_signal(true)
	
	
func addResolutions():
	var currentResolution = get_window().get_size()
	var ID = 0
	
	for r in Resolutions:
		resolutionBtn.add_item(r, ID)
		
		print(str(currentResolution))
		if Resolutions[r] == currentResolution:
			print("gfgdffgd")
			resolutionBtn.select(ID)
		
		ID += 1

func _on_item_selected(index):
	var itemID = resolutionBtn.get_item_text(index)
	get_window().set_size(Resolutions[itemID])
	Center_Window()
	
func Center_Window():
	var Center_Screen = DisplayServer.screen_get_position()+DisplayServer.screen_get_size()/2
	var Window_Size = get_window().get_size_with_decorations()
	get_window().set_position(Center_Screen-Window_Size/2)

func _on_fullscreen_btn_toggled(toggled_on):
	if toggled_on:
		get_window().set_mode(Window.MODE_FULLSCREEN)
	else:
		get_window().set_mode(Window.MODE_WINDOWED)

Try assigning to Window.size, e.g.

Window.size = Vector2i(1024x768)

instead of get_window().set_size) as the docs recommend.

Doing that gives me the error

Invalid set index ‘size’ (on base: ‘Window’) with value of type ‘Vector2i’

I have no idea at this point. I cant test really test if this works on a smaller screen